HIVE-利用ow_number() OVER(PARTITION BY)函数介绍求TOP-K


http://blog.csdn.net/631799/article/details/7419797

第一句话:

select row_number() over (partition by month order by ref_host_cnts desc;
partition:按照month分成区块
order by :排序实在partition分成的区块中分别进行。
row_number():对各个分区分别添加编号,类似于rownum的递增序列
 
 
嵌套后获取TOPK,获取每个月前两名的数据
select t.hour, t.od, t.ref_host, t.ref_host_cnts from
 (select ref_host, ref_host_cnts,month as hour,
row_number() over (partition by month order by ref_host_cnts desc) as od
from dw_ref_host_visit_cnts_h) t where od<=3;


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM