BigQuery COUNT(*)... WHERE NOT(...)返回令人困惑的结果

时间:2015-10-28 12:57:17

标签: google-bigquery

我有一个包含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的查询会返回0IS NULL会返回正确的结果?

1 个答案:

答案 0 :(得分:3)

“为什么WHERE NOT的查询返回0而IS NULL返回正确的结果?”

因为

SELECT null != 'anything'

返回'null',而不是'false'。