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