Postgresql 使用postgres窗口函数复制行
postgres文档()讨论了窗口函数 在他们的例子中:Postgresql 使用postgres窗口函数复制行,postgresql,psql,Postgresql,Psql,postgres文档()讨论了窗口函数 在他们的例子中: 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
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)
工资|总额
--------+-------
3500 | 3500
3900 | 7400
4200 | 11600
4500 | 16100
4800 | 25700在中的框架子句中使用行
,而不是默认的范围
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