sql求topN

需求

       统计每小时内host网址的topN

 

解答

      步骤一:对每个小时内的来访host次数倒序排序标号

select ref_host,pv_ref_host_hour,concat(month,day,hour),row_number() over (partition by concat(month,day,hour) order by pv_ref_host_hour desc) as od from pvs_ref_host_hour;

sql求topN_第1张图片

 

     步骤二:求Top3

select ref_host,pv_ref_host_hour,concat(month,day,hour),row_number() over (partition by concat(month,day,hour) order by pv_ref_host_hour desc) as od from pvs_ref_host_hour  where od <= 3;

sql求topN_第2张图片

你可能感兴趣的:(sql)