Z05 - 031、分组 TOP 问题(分组函数)

初学耗时:0.5h

注:CSDN手机端暂不支持章节内链跳转,但外链可用,更好体验还请上电脑端。

一、分组 TOP 问题(分组函数)
  1.1  对每个小时内的来访 host 次数倒序排序标号。
  1.2  编写 hql 取各小时的 ref_host 访问次数 topn。



记忆词:

  分组函数、row_number()

Z05 - 999、网站流量日志分析


ギ 舒适区ゾ || ♂ 累觉无爱 ♀





一、分组 TOP 问题(分组函数)

  • 需求描述:统计每小时各来访 host 的产生的 pvs 数最多的前 N 个(topN)。
  • row_number()函数
  1. 语法:row_number() over (partition by xxx order by xxx) rank,rank 为分组的别名,相当于新增一个字段为 rank。
  2. partition by 用于分组,比方说依照 sex 字段分组。
  3. order by 用于分组内排序,比方说依照 sex 分组后,组内按照 age 排序。
  4. 排好序之后,为每个分组内每一条分组记录从 1 开始返回一个数字。
  5. 取组内某个数据,可以使用 where 表名,rank>x 之类的语法去取。
  1.1 ~ 对每个小时内的来访 host 次数倒序排序标号。
select ref_host,ref_host_cnts,concat(month,day,hour),
row_number() over (partition by concat(month,day,hour) order by 
ref_host_cnts desc) as od from dw_pvs_refererhost_everyhour;

alt

  1.2 ~ 编写 hql 取各小时的 ref_host 访问次数 topn。
drop table dw_pvs_refhost_topn_everyhour;

create table dw_pvs_refhost_topn_everyhour(
	hour string,
	toporder string,
	ref_host string,
	ref_host_cnts string
)partitioned by(datestr string);

insert into table dw_pvs_refhost_topn_everyhour partition(datestr='20181101')

select t.hour,t.od,t.ref_host,t.ref_host_cnts from
(select ref_host,ref_host_cnts,concat(month,day,hour) as hour,
row_number() over (partition by concat(month,day,hour) order by ref_host_cnts desc) as od 
from dw_pvs_refererhost_everyhour) t where od<=3;

alt



葡萄美酒夜光杯,欲饮琵琶马上催。

- - - - - - - - - - - - - - - - - - - - - - - - - - - -



^ 至此,分组 TOP 问题(分组函数)完成。


- - - - - - - - - - - - - - - - - - - - - - - - - - - -


※ 世间诱惑何其多,坚定始终不动摇。

使用UML建模时一般分为_____设计、逻辑设计和物理设计三大部分。


用例视图
alt



葡萄美酒夜光杯,欲饮琵琶马上催。

- - - - - - - - - - - - - - - - - - - - - - - - - - - -


注:CSDN手机端暂不支持章节内链跳转,但外链可用,更好体验还请上电脑端。

我知道我的不足,我也知道你的挑剔,但我就是我,不一样的烟火,谢谢你的指指点点,造就了我的点点滴滴:)!



葡萄美酒夜光杯,欲饮琵琶马上催。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值