postgres文档(
http://www.postgresql.org/docs/9.1/static/tutorial-window.html)讨论了窗口函数.
在他们的例子中:
SELECT salary,sum(salary) OVER (ORDER BY salary) FROM empsalary;
重复处理如下:
salary | sum --------+------- 3500 | 3500 3900 | 7400 4200 | 11600 4500 | 16100 4800 | 25700 <-- notice duplicate rows have the same value 4800 | 25700 <-- SAME AS ABOVE 5000 | 30700 5200 | 41100 <-- same as next line 5200 | 41100 <-- 6000 | 47100 (10 rows)
你如何做同样的事情,以便重复的行没有给出相同的值?换句话说,我希望这个表看起来如下:
salary | sum --------+------- 3500 | 3500 3900 | 7400 4200 | 11600 4500 | 16100 4800 | 20900 <-- not the same as the next line 4800 | 25700 <-- 5000 | 30700 5200 | 35900 <-- not the same as the next line 5200 | 41100 <-- 6000 | 47100 (10 rows)
使用frame子句中的行而不是默认范围
select salary,sum(salary) over ( order by salary rows unbounded preceding ) from empsalary ; salary | sum --------+------- 3500 | 3500 3900 | 7400 4200 | 11600 4500 | 16100 4800 | 20900 4800 | 25700 5000 | 30700 5200 | 35900 5200 | 41100 6000 | 47100
http://www.postgresql.org/docs/current/static/sql-expressions.html#SYNTAX-WINDOW-FUNCTIONS
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。