加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

PostgreSQL计算行之间的差异

发布时间:2020-12-13 16:33:24 所属栏目:百科 来源:网络整理
导读:我尝试使用查询来计算字段中的行之间的差异: Illustrations:input:year,month,fixesoutput:increase year | month | fixes | increase ------+-------+----------+----------- 2006 | 04 | 1 | 0 2006 | 05 | 4 | 3 2006 | 06 | 3 | -1 将列增加为固定中相
我尝试使用查询来计算字段中的行之间的差异:
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,fixes,fixes - lag(fixes) over (order by year,month) as increase,from the_table;

有关详细信息,请参阅手册:
http://www.postgresql.org/docs/current/static/tutorial-window.html

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读