参考这篇博客而写:http://blog.csdn.net/longshenlmj/article/details/50525385
本 Hive 语句的目的是统计中国每个省份下所有城市记录出现总次数为前5的结果。
hive -e "
select bb.*
from
(
select country_name,
province_name,
city_name,
pv_cnt,
row_number() over (partition by country_name,province_name order by pv_cnt desc) rank_code
from
(select b.country_name,
b.province_name,
b.city_name,
count(1) as pv_cnt
from table_a a
join table_b b
on a.area_id = b.area_id
where a.dt = '某天' and b.country_name = '中国'
group by b.country_name,
b.province_name,
b.city_name ) aa
) bb
where bb.rank_code <= 5;"