我有一个每天运行的查询,突然它停止输出结果。它不会输出错误,只会输出结果。
请注意,此查询包含一个NOT IN
运算符。
答案 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 JOIN
或NOT 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