我的查询有一个NOT IN,突然停止显示结果

时间:2018-11-14 20:22:04

标签: google-bigquery

我有一个每天运行的查询,突然它停止输出结果。它不会输出错误,只会输出结果。

请注意,此查询包含一个NOT IN运算符。

1 个答案:

答案 0 :(得分:1)

这是NOT IN行为的已知问题,请查看它的MySQL版本:

使用BigQuery:

WITH data AS (
  SELECT * FROM UNNEST([1,2,3]) x
), data2 AS (
  SELECT * FROM UNNEST([1,2]) x
)

SELECT * FROM data
WHERE x NOT IN (SELECT * FROM data2)

3

但是如果data2中为空,则

WITH data AS (
  SELECT * FROM UNNEST([1,2,3]) x
), data2 AS (
  SELECT * FROM UNNEST([1,2,null]) x
)

SELECT * FROM data
WHERE x NOT IN (SELECT * FROM data2)

# no results

相反,您可以执行LEFT JOINNOT EXISTS

WITH data AS (
  SELECT * FROM UNNEST([1,2,3]) x
), data2 AS (
  SELECT * FROM UNNEST([1,2]) x
)

SELECT * FROM data a
WHERE NOT EXISTS (SELECT * FROM data2 b WHERE a.x=b.x)

3