过滤计数(*)超过一定数量?

问题描述 投票:2回答:2

如果我尝试运行下面的任何一个查询,那么我收到消息:

编译语句时出错:FAILED:ParseException 5:0在'nino_dtkn'附近'where'处缺少EOF

这告诉我,我不能在同一个查询中使用新创建的count变量。

我的结论是否正确?

我该怎么办才能修复它?

我不想创建一个新表 - 我想将它用作子查询以合并到第二个表。

select count(*) as cnt, 
                   [variable 1]
from [source table]
group by [variable 1]
where count(*) >= 20; 

select count(*) as cnt, 
                   [variable 1]
from [source table]
group by [variable 1]
where cnt >= 20;
hive count where
2个回答
1
投票

使用HAVING条款

select count(*) as cnt,[variable 1]
from [source table]
group by [variable 1]
having count(*) >= 20;

0
投票

我不确定你的预期结果。 WHERE CLAUSE应该总是在GROUP BY FUNCTION之前来。

因此,您的查询可以重写为下面提到的那个:

select count(*) as cnt,[variable 1]
from [source table]
where count(*) >= 20
group by [variable 1]
; 
© www.soinside.com 2019 - 2024. All rights reserved.