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

时间:2019-04-10 12:27:15

标签: hive count where

如果我尝试运行以下任一查询,则会收到以下消息:

  

编译语句时出错:失败:ParseException行5:0   在“ nino_dtkn”附近的“位置”缺少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;

2 个答案:

答案 0 :(得分:1)

使用HAVING子句

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

答案 1 :(得分:0)

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

因此您的查询可以重写为以下提到的内容:

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