【问题标题】:Using OR statment in condition sqlite database在条件 sqlite 数据库中使用 OR 语句
【发布时间】:2014-02-11 13:59:38
【问题描述】:

我正在尝试执行此查询,但无法在 sqlite android 数据库中工作

"select CLFPSid from CheckLists where CLFPid = "+ section + " and ActionDate ='"+Date+"'and CLFPSid = 0 or 3 or 4 or 5"

使用 OR 语句的问题,注意 CLFPSid 是 integer 类型。

如何使用或sqlite条件语句?

【问题讨论】:

    标签: java android mysql database sqlite


    【解决方案1】:

    你不会写

    CLFPSid = 0 or 3 or 4 or 5
    

    你应该使用 IN 子句:

    CLFPSid IN (0, 3, 4, 5);
    

    【讨论】:

    • +1, INstatement or statement or statement 更好的标准
    【解决方案2】:

    如下更改您的查询

     "select CLFPSid from CheckLists where CLFPid = "+ section + " 
               and ActionDate ='"+Date+"'and CLFPSid = 0 or CLFPSid = 3 
                                                  or CLFPSid = 4 or CLFPSid = 5"
    

    【讨论】:

    • 您不需要(在最后一个and 之后和)在= 5 之后吗?
    • @peter.petrov 不是必须的。
    • IN 语句更好更简单
    • 嗯。我认为这是必须的,因为a and b and c1 or c2 or c3 将被视为(a and b and c1) or c2 or c3 而不是a and b and (c1 or c2 or c3)。不?我认为 OP 想要后者。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-05-28
    • 2019-03-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-01
    • 1970-01-01
    相关资源
    最近更新 更多