我的问题陈述是
“找出每个州人口最多的前2个地区”
数据就像
输入
我的预期产出是
输出
我尝试了很多查询和子查询,但结果是子查询出现sql错误
有人能帮我得到这个结果吗?
提前谢谢。
我试过的问题
选择state_name,(select concat_ws(',','collect_set(dist_name as string))from population where state_name=state_name group by state order by population desc 2)
按州/市/自治区名称列出的人口组
选择
state\u name,concat\u ws(',',collect\u set(cast(dist\u name as string)))
from population where population.dist\u name in(select dist\u name from(select dist\u name,max(b.population)as total from population b where state\u name=b.state\u name group by b.dist\u name,b.dist\u name order by total desc limit 2)as dist\u name)按州分组
1条答案
按热度按时间6ju8rftf1#
下面是问题-
下面是样本数据的结果-