我有一个包含device
列的表格,可能是' P',' T'或NULL,但像device NOT IN('P', 'T')
这样的条件似乎错过了带NULL的行。可以通过以下查询进行演示
$ bq query 'SELECT count(*) FROM t'
+----------+
| f0_ |
+----------+
| 29542063 |
+----------+
$ bq query "SELECT count(*) FROM t WHERE device = 'P' OR device = 'T'"
+---------+
| f0_ |
+---------+
| 8268436 |
+---------+
$ bq query "SELECT count(*) FROM t WHERE NOT (device = 'P' OR device = 'T')"
+-----+
| f0_ |
+-----+
| 0 |
+-----+
$ bq query "SELECT count(*) FROM t WHERE device IS NULL"
+----------+
| f0_ |
+----------+
| 21273627 |
+----------+
为什么WHERE NOT
的查询会返回0
而IS NULL
会返回正确的结果?
答案 0 :(得分:3)
“为什么WHERE NOT的查询返回0而IS NULL返回正确的结果?”
因为
SELECT null != 'anything'
返回'null',而不是'false'。