postgresql – 带有postgres窗口函数的重复行
发布时间:2020-12-13 18:05:37 所属栏目:百科 来源:网络整理
导读: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 |
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 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- c# – Active Directory列表OU
- ruby-on-rails – 有没有办法重构将多态关联解压缩到其模型
- [React] Build a slide deck with mdx-deck using Markdown
- 基于jquery实现ajax无刷新评论
- C# WinForm捕获全局变量异常 SamWang解决方法
- ios – 创建UICollectionViewCell时子视图框不正确
- 【软件周刊第 30 期】PostgreSQL 10 首个公测版发布;Eclip
- ruby-on-rails-3 – 在ActiveModel中使用before_validation
- C#面板不可见
- 使用Playground快速练习Swift语法--类与面向对象