CASE WHEN 判断中以嵌套子查询为条件的 Hive SQL 查询
正如标题,我的查询如下:
SELECT
COUNT(
DISTINCT (CASE WHEN id IN (
SELECT DISTINCT id
FROM some_table
WHERE year = 2019
AND month IN (1, 2, 3)
) tmp AND (*OTHERS CONDITIONS*) THEN id END)
) AS devices
FROM some_table
WHERE year = 2019
AND month IN (1, 2, 3);
但是,我不断收到此错误:
cannot recognize input near 'SELECT' 'DISTINCT' 'id' in expression specification
我该如何解决?
AS the title, my query is like:
SELECT
COUNT(
DISTINCT (CASE WHEN id IN (
SELECT DISTINCT id
FROM some_table
WHERE year = 2019
AND month IN (1, 2, 3)
) tmp AND (*OTHERS CONDITIONS*) THEN id END)
) AS devices
FROM some_table
WHERE year = 2019
AND month IN (1, 2, 3);
However, I kept receiving this error:
cannot recognize input near 'SELECT' 'DISTINCT' 'id' in expression specification
How can I workaround?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你不能像这样使用子查询。将子查询更改为 join 并在以防万一时使用它。
you can not use subquery like this. Change the subquery to join and use it in case when.