oracle查询每行顺序求和 [英] oracle query sequential summation per rows

查看:49
本文介绍了oracle查询每行顺序求和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想问一个类似下表的查询吗?

I would like to ask to make a query like the following table?

-------------------------------------
ID   Date        Input  Output  Total
-------------------------------------
1   2016-05-01  10       0      10
1   2016-05-02  2       -1      11
1   2016-05-03  0       -5      6
1   2016-05-04  0       -1      5 

假设我有一个表"table_a",该表具有一列(ID,名称,日期,输入,输出).如何创建具有上述结果的查询.

assume I have a table "table_a" that has a column (ID, name, date, input, output). how to create query with results as above.

推荐答案

您可以使用SUM OVER函数:

SELECT *,
    SUM(Input + Output) OVER(PARTITION BY ID ORDER BY Date) AS Total
FROM table_a

这篇关于oracle查询每行顺序求和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆