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

时间:2015-08-18 20:09:42

标签: sql database postgresql

如何选择postgresql中的col1 = 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' |

1 个答案:

答案 0 :(得分:2)

SELECT * FROM "Media" 
WHERE "MediaId" = $1 
AND ("AType" = 0 OR "BType" = 0 OR "C" is not null)

您应该使用is not null代替!=null