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;
(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;