[英]PostgreSQL calculate difference between rows
我嘗試使用查詢計算字段中行之間的差異:
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;
有關詳細信息,請參閱手冊:
http://www.postgresql.org/docs/current/static/tutorial-window.html
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.