实例1 )按网计算近3月累计/平均缴费人数2 )流量溢出人数比例
1 .按网计算近3月累计/平均缴费人数select net_type、pay_date_first_zy缴费时间、count(1)人数, sum(count(1) ) over (partitionbynet _ typeorderbypay _ date _ first _ zyrowsbetween1preceding and1following ) )最近三个月的累计peorderbypay _ date _ first _ zyrowsbetween1preceding and1 following ) ) ) ) 65 1)近3月的平均缴费人数froman RPT.RPT _ LAN pay_date_first _ zyorderbynet _ type、pay _ date _ first _ zyorderbynet _ type、pay _ date _ fir
结果如下。
从会计期间为2019.10来看,2019.10没有上月的值,因此2019.10人的人数为201911人的人数=累计缴费人数,3 1=4。
会计期间为201911时,使用201910 201911 201911人数=累计缴费人数,3 1 3=7。
2 .流量溢出情况人数占比select gprs_more_type流量溢出频率,row_number(over ) orderbycount(1)DESC )人数排名,count)1) sum(count(1) ) over ) orderbycount )1) rowsbetweenunboundedprecedingandcurrentrow ) ) sum1 --从第一行到当前行的总结。 sum(count(1) ) over ) orderbycount )1) rowsbetweencurrentrowandunboundedfollowing ) sum2 --从当前行到最后一行的总结。 从sum(count(1) ) over ) orderbycount )1) rows between1precedingandcurrentrow ) sum3 --当前行的上一行) rownum-1 )到当前行的总结sum(count(1) ) over ) orderbycount )1) rows between1preceding and1following ) sum4 --从当前行的上一行(rownum-1 )到当前行的下一行owsbetweenunboundedprecedingandunboundedfollowing ) sum5 --每行的数据窗口从第一行到最后一行都是from
求人数占有率直接按人数/sum5即可。
这里给出了几种分组的合计方法。 当然,如果有多个维,也可以将PARTITION BY添加到over中,并使用其他聚合函数,如max和min,以及合计。
下一篇:【gp数据库】你可能不知道,超实用的函数