在Oracle中查询运行总和 [英] Query in Oracle for running sum

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

问题描述

我需要将结果集与前一条记录和当前记录的总和拉出.

I need to pull the result set with sum of the previous record and current record.

逻辑

我的表有一个键列C1和一个数字列C2.我需要类似以下示例的结果.我需要3列作为输出,其中1列是运行总和.前两列与第三列的来源相同,但

My table is having one key column C1 and a numeric column C2. I need a result like below example. I need 3 columns as the out put out which 1 columns is with running sum. First two columns are same as source with the thrid columns but

  • C3的第一条记录= C2的第一条记录.
  • 第二条记录C3 =第一条记录C2 +第二条记录C2";
  • 第三条记录C3 =第一条记录C2 +第二条记录C2 +阈值记录C2"

,并且应继续记录所有记录.

and it should continue for all the records.

例如. 我有一个像

C1     C2
---------
a       1
b       2
c       3

我需要如下输出

C1   C2   C3
-------------
a    1    1
b    2    3
c    3    6

推荐答案

select c1, c2, sum(c2) over (order by c2) c3
  from table_name

这篇关于在Oracle中查询运行总和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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