我没有结果。如何在SQLite中的where
子句中包含布尔条件?
我试过这些
"Select * from table where col = 1"
"Select * from table where col = '1'"
"Select * from table where col = true"
"Select * from table where col = 'true'"
"Select * from table where col = 'True'"
"Select * from table where col is True"
无。我甚至尝试在查询函数中包含“true”作为whereArgs。
我该如何解决?
答案 0 :(得分:15)
答案 1 :(得分:1)
SQLite version 3.7.4
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> CREATE TABLE "stack_test" ("id" INTEGER, "bool_col" boolean);
sqlite> insert into stack_test values(1,'t');
sqlite> insert into stack_test values(2,'f');
sqlite> insert into stack_test values(3,'1');
sqlite> insert into stack_test values(4,'0');
sqlite> insert into stack_test values(5,1);
sqlite> insert into stack_test values(6,0);
sqlite> insert into stack_test values(7,banana);
Error: no such column: banana
sqlite> insert into stack_test values(7,'banana');
sqlite> .headers on
sqlite> select * from stack_test;
id|bool_col
1|t
2|f
3|1
4|0
5|1
6|0
7|banana
sqlite> select * from stack_test where bool_col=t;
Error: no such column: t
sqlite> select * from stack_test where bool_col='t';
id|bool_col
1|t
sqlite> select * from stack_test where bool_col=0;
id|bool_col
4|0
6|0
sqlite> select * from stack_test where bool_col=1;
id|bool_col
3|1
5|1
sqlite> select * from stack_test where bool_col=true;
Error: no such column: true
sqlite> select * from stack_test where bool_col=banana;
Error: no such column: banana
sqlite> select * from stack_test where bool_col='banana';
id|bool_col
7|banana
sqlite>
sqlite> .schema stack_test
CREATE TABLE "stack_test" ("id" INTEGER, "bool_col" boolean);
sqlite>
答案 2 :(得分:0)
SQLite中没有真正的布尔值。如果您使用SQLite Administrator创建它,请按以下步骤操作:
Select * from table where col is 'Y'
答案 3 :(得分:0)
这很有效 “从表中选择*,其中col ='true'”