【问题标题】:How to select if `col1 = 0 OR col2 = 0 OR col3 != null` statement in postgresql?如何在 postgresql 中选择 if `col1 = 0 OR col2 = 0 OR col3 != null` 语句?
【发布时间】:2015-08-19 04:10:54
【问题描述】:

postgresql中如何选择ifcol1 = 0 OR col2 = 0 OR col3 != null语句?

var query = 'SELECT * FROM "Media" WHERE "MediaId" = $1 AND ("AType" = 0 OR "BType" = 0 OR "C" != null)';


CREATE TABLE IF NOT EXISTS "Media"(
"MediaId" SERIAL NOT NULL,
"AType" integer,
"BType" integer,
"C" varchar,
PRIMARY KEY ("MediaId")
);



MediaId | AType | BType | C
0 | 0 |   |   |
1 | 1 |   |   |
2 | 2 |   |   |
3 |   | 0 |   |
4 |   | 1 |   |
5 |   |   | 'f' |

【问题讨论】:

    标签: sql database postgresql


    【解决方案1】:
    SELECT * FROM "Media" 
    WHERE "MediaId" = $1 
    AND ("AType" = 0 OR "BType" = 0 OR "C" is not null)
    

    您应该使用is not null 而不是!=null

    【讨论】:

    • 打我一拳!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-12-05
    • 2018-10-13
    • 2019-05-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-20
    相关资源
    最近更新 更多