HIve窗口函数之CUME_DIST,PERCENT_RANK

本博客使用数据与。。一致。

1、CUME_DIST函数

CUME_DIST 小于等于当前值的行数/分组内总行数

SELECT 
cookieid,
createtime,
pv,
CUME_DIST() OVER(ORDER BY pv) AS rn1,
CUME_DIST() OVER(PARTITION BY cookieid ORDER BY pv) AS rn2 
FROM cookies;

结果:

HIve窗口函数之CUME_DIST,PERCENT_RANK_第1张图片

2、PERCENT_RANK函数

PERCENT_RANK 分组内当前行的RANK值-1/分组内总行数-1

SELECT 
cookieid,
createtime,
pv,
PERCENT_RANK() OVER(ORDER BY pv) AS rn1,   --分组内
RANK() OVER(ORDER BY pv) AS rn11,          --分组内RANK值
SUM(1) OVER(PARTITION BY NULL) AS rn12,     --分组内总行数,所有数据都是一组
PERCENT_RANK() OVER(PARTITION BY cookieid ORDER BY pv) AS rn2 
FROM cookies;

结果:

HIve窗口函数之CUME_DIST,PERCENT_RANK_第2张图片

你可能感兴趣的:(Hive,Hive,CUME_DIST,PERCENT_RANK)