筛选器计数(*)超过某个数字?

lh80um4z  于 2021-06-24  发布在  Hive
关注(0)|答案(2)|浏览(402)

如果我尝试运行以下任何一个查询,则会收到以下消息:
编译语句时出错:失败:parseexception行5:0在“nino\u dtkn”附近的“where”缺少eof
这意味着我不能在同一个查询中使用新创建的count变量。
我的结论正确吗?
我能做些什么来修复它?
我不想创建一个新表-我想用它作为子查询合并到第二个表上。

  1. select count(*) as cnt,
  2. [variable 1]
  3. from [source table]
  4. group by [variable 1]
  5. where count(*) >= 20;
  6. select count(*) as cnt,
  7. [variable 1]
  8. from [source table]
  9. group by [variable 1]
  10. where cnt >= 20;
sirbozc5

sirbozc51#

我不确定你的预期结果。 WHERE CLAUSE 应该总是在前面 GROUP BY FUNCTION .
因此,您的查询可以重写为下面提到的查询:

  1. select count(*) as cnt,[variable 1]
  2. from [source table]
  3. where count(*) >= 20
  4. group by [variable 1]
  5. ;
7hiiyaii

7hiiyaii2#

使用having子句

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

相关问题