【发布时间】:2017-03-30 14:19:10
【问题描述】:
table1 数据样本:
year month day utmsource
2017 03 26 NULL
2017 03 27 NULL
2017 03 27 facebook
2017 03 27 newsletter
2017 03 27 banner
2017 03 27 facebook
预期选择:
year month day utmsource
2017 03 27 NULL
2017 03 27 newsletter
2017 03 27 banner
我的 Hive 查询:
-- result = 0, it did not include the NULL utmsource record
SELECT SUM(CASE WHEN utmsource IS NULL THEN 1 ELSE 0 END) as amountnull
FROM table1
WHERE year=2017 AND month=03 AND day=27 AND NOT utmsource="facebook"
-- result = 1 the NULL utmsource record is included
SELECT SUM(CASE WHEN utmsource IS NULL THEN 1 ELSE 0 END) as amountnull
FROM table1
WHERE year=2017 AND month=03 AND day=27 AND (utmsource IS NULL OR NOT utmsource="facebook")
-- also returns 0, the NULL utmsource record is not included
SELECT SUM(CASE WHEN utmsource IS NULL THEN 1 ELSE 0 END) as amountnull
FROM table1
WHERE year=2017 AND month=03 AND day=27 AND NOT utmsource <=> 'facebook';
问题:
- 有人能解释一下这种行为吗?
- 我可以将设置更改为 检索查询 2 的结果而不添加额外的 OR 我的查询中的功能? => 不等于在结果中包含空值
【问题讨论】:
-
NOT NULL-->NULL--> 不正确 -
这段代码一团糟。请提供数据样本。
标签: sql hadoop hive apache-spark-sql bigdata