初学耗时:0.5h
注:CSDN手机端暂不支持章节内链跳转,但外链可用,更好体验还请上电脑端。
一、分组 TOP 问题(分组函数)
1.1 对每个小时内的来访 host 次数倒序排序标号。
1.2 编写 hql 取各小时的 ref_host 访问次数 topn。
记忆词:
分组函数、row_number()
一、分组 TOP 问题(分组函数)
- 需求描述:统计每小时各来访 host 的产生的 pvs 数最多的前 N 个(topN)。
- row_number()函数
- 语法:row_number() over (partition by xxx order by xxx) rank,rank 为分组的别名,相当于新增一个字段为 rank。
- partition by 用于分组,比方说依照 sex 字段分组。
- order by 用于分组内排序,比方说依照 sex 分组后,组内按照 age 排序。
- 排好序之后,为每个分组内每一条分组记录从 1 开始返回一个数字。
- 取组内某个数据,可以使用 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;
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;
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
^ 至此,分组 TOP 问题(分组函数)完成。
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
※ 世间诱惑何其多,坚定始终不动摇。
使用UML建模时一般分为_____设计、逻辑设计和物理设计三大部分。
…
用例视图
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
注:CSDN手机端暂不支持章节内链跳转,但外链可用,更好体验还请上电脑端。
我知道我的不足,我也知道你的挑剔,但我就是我,不一样的烟火,谢谢你的指指点点,造就了我的点点滴滴:)!