SQLite中“不相等”的语法是什么?


112
 Cursor findNormalItems = db.query("items", columns, "type=?", 
                                   new String[] { "onSale" });

我想返回指向未销售商品的光标,我该怎么做?谢谢!

Answers:


201

官方文档中

非等于运算符可以是!=<>

因此,您的代码变为:

Cursor findNormalItems = db.query("items", columns, "type != ?", 
                                  new String[] { "onSale" });   

9
在我看来,!=看起来更专业-并且与===运算符更加一致。
ban-geoengineering

为什么我必须添加“ OR'mycolumn'is NOT NULL?当我使用where子句NOT EQUAL进行查询吗?
ThierryC

3
@ ban-geoengineering <>是SQL Ansi标准,!=不是。当然<>更专业
edc65 '18

@ ban-geoengineering,这是一堆注释,提供了使用!=or的参数<>

9

您应该在比较器中使用非等号运算符: "type!=?""type<>?"


By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.