在配置单元中,我想选择users>=40
的记录。我的表格列由字段userid
组成。所以我用了
select title,sum(rating),count(userid) from table_name where count(userid)>=40
group by title order by rating desc
但它显示错误,就像你不能在where子句中使用count。我也试过使用像
这样的别名 select title,sum(rating) as ratings,count(userid) as users where users>=40 group by title order by ratings desc
此处我还遇到错误,显示用户不是表中的列名。 我需要获得最少40位用户的最高评分标题
答案 0 :(得分:2)
您希望拥有子句:
select title, sum(rating), count(userid)
rom table_name
group by title
having count(userid) >= 40
order by sum(rating) desc;
在Hive中,您可能需要使用列别名,但是:
select title, sum(rating) as rating, count(userid) as cnt
rom table_name
group by title
having cnt >= 40
order by rating desc;