如果我尝试运行下面的任何一个查询,那么我收到消息:
编译语句时出错: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;
使用HAVING条款
select count(*) as cnt,[variable 1]
from [source table]
group by [variable 1]
having count(*) >= 20;
我不确定你的预期结果。 WHERE CLAUSE
应该总是在GROUP BY FUNCTION
之前来。
因此,您的查询可以重写为下面提到的那个:
select count(*) as cnt,[variable 1]
from [source table]
where count(*) >= 20
group by [variable 1]
;