码迷,mamicode.com
首页 > 数据库 > 详细

postgresql分析函数

时间:2019-04-23 09:51:15      阅读:205      评论:0      收藏:0      [点我收藏+]

标签:range   sele   集合   span   blog   course   order by   添加   分析函数   

参考:https://blog.csdn.net/haohaizijhz/article/details/83340814

SELECT uid, odate, num,
sum(num) over (),
sum(num) over (partition by uid),
sum(num) over (partition by uid,odate),
sum(num) over (order by uid,odate),
sum(num) over (order by uid,odate,num),
rank() over (partition by uid order by odate),
rank() over (partition by uid order by odate,num),
sum(num) over (partition by uid order by odate),
lead(num,1,0) OVER (partition by uid order by odate),
-num+lead(num,1,0) OVER (partition by uid order by odate),
1.0*num/sum(num) over() rate
FROM dev."order";

技术图片

SELECT name, course, score,
sum(score) over (order by course rows between unbounded preceding and current row),
sum(score) over (order by course range between unbounded preceding and current row)
  FROM dev.score;

技术图片

ORDER BY子句:分析函数中ORDER BY的存在将添加一个默认的开窗子句,这意味着计算中所使用的行的集合是当前分区中当前行和前面所有行;没有ORDER BY时,默认的窗口是全部的分区。

postgresql分析函数

标签:range   sele   集合   span   blog   course   order by   添加   分析函数   

原文地址:https://www.cnblogs.com/sijizhen/p/10754278.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!