我try 使用查询计算字段中行之间的差异:
Illustrations: input:year,month,fixes output:increase year | month | fixes | increase ------+-------+----------+----------- 2006 | 04 | 1 | 0 2006 | 05 | 4 | 3 2006 | 06 | 3 | -1
通过修正中相邻行之间的差值增加列作为输出.
我try 使用查询计算字段中行之间的差异:
Illustrations: input:year,month,fixes output:increase year | month | fixes | increase ------+-------+----------+----------- 2006 | 04 | 1 | 0 2006 | 05 | 4 | 3 2006 | 06 | 3 | -1
通过修正中相邻行之间的差值增加列作为输出.
这就是窗口函数的用途:
select year,
month,
fixes,
fixes - lag(fixes) over (order by year, month) as increase,
from the_table;
For more details please see the manual:
http://www.postgresql.org/docs/current/static/tutorial-window.html