English 中文(简体)
整个qlite表的简单数
原标题:Simple math on entire sqlite table

让我们采取这一简单表格:

CREATE TABLE correlation (  1  REAL,  2  REAL,  3  REAL)
INSERT INTO correlation VALUES ( 1.0 , -0.4 , 0.6 )
INSERT INTO correlation VALUES ( -0.4 , 1.0 , 0.2 )
INSERT INTO correlation VALUES ( 0.6 , 0.2 , 1.0 )

现在希望在囚室里形成一种观点并做一些简单的数学:

CREATE VIEW correlation_codes AS SELECT 
CASE 
WHEN * > 0 THEN 3
WHEN * < 0 THEN 5
WHEN * == 0 THEN 8
WHEN * == 1.0 THEN 4
ELSE 99
END
FROM correlation

预期成果:

 1.0  -0.4  0.6
-0.4   1.0  0.2
 0.6   0.2  1.0

成为:

 4      5     3
 5      4     3
 3      3     4

我不能在化学文摘社国际协会中使用*,但我想在整个桌旁有一个化学文摘社。

我应该做些什么?

问题回答

首先,你为什么将数字(人数、oka、可直接投向数字的插图)作为栏目? 这只是要求麻烦,特别是在<条码>、<>条/条码>或<条码>、、声明(<条码>、WHERE 1 >0中,最好能找到。

第二,你在一份<条码>说明中重新正确,因为你可以使用<条码>*。 页: 1 然而,当一栏名数(基本上)为:

select case when 1 >0 then 3 when 1 <0 then 5 when 1 ==0 then 8 when 1 ==1.0 then 4 else 99 end from correlation;

产量

3
3
3

相反,请举一栏号:

sqlite> create table correlation2 (c1 real,c2 real,c3 real);
sqlite> insert into correlation2 values (1.0,-0.4,0.6);
sqlite> insert into correlation2 values (-0.4,1.0,0.2);
sqlite> insert into correlation2 values (0.6,0.2,1.0);

现在,案件陈述表明:

sqlite> select case when c1>0 then 3 when c1<0 then 5 when c1==0 then 8 when c1==1.0 then 4 else 99 end from correlation2;
case when c1>0 then 3 when c1<0 then 5 when c1==0 then 8 when c1==1.0 then 4 else 99 end
3
5
3

现在,你想要一栏数值。

4
5
3

However, that s not how the case statement works: Since 1.0>1, the first branch of the case statement is evaluated (and hence the first entry is assigned to 3, not 4). Is this what you meant?

sqlite> select case when c1>0 and c1!=1 then 3 when c1<0 then 5 when c1==0 then 8 when c1==1 then 4 else 99 end from correlation2;
case when c1>0 and c1!=1 then 3 when c1<0 then 5 when c1==0 then 8 when c1==1 then 4 else 99 end
4
5
3

You could create a UDF and run each column through the UDF, to do the transformation. I think you can use the UDF in a view:

           create view myView as
           select udf(col1), udf(col2), udf(col3) ...
           from T




相关问题
sqlite3 is chopping/cutting/truncating my text columns

I have values being cut off and would like to display the full values. Sqlite3 -column -header locations.dbs " select n.namelist, f.state, t.state from names n left join locations l on l.id = n.id ...

Entity Framework with File-Based Database

I am in the process of developing a desktop application that needs a database. The application is currently targeted to SQL Express 2005 and works wonderfully. However, I m not crazy about having ...

Improve INSERT-per-second performance of SQLite

Optimizing SQLite is tricky. Bulk-insert performance of a C application can vary from 85 inserts per second to over 96,000 inserts per second! Background: We are using SQLite as part of a desktop ...

Metadata for columns in SQLite v2.8 (PHP5)

How can I get metadata / constraints (primary key and "null allowed" in particular) for each column in a SQLite v2.8 table using PHP5 (like mysql_fetch_field for MySql)? sqlite_fetch_column_types (OO:...

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签