oracle query sequential summation per rows

前端 未结 2 426
时光说笑
时光说笑 2020-12-21 18:51

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

-------------------------------------
ID   Date        Input  Output  Total
-------------------         


        
相关标签:
2条回答
  • 2020-12-21 19:28

    You can use SUM OVER function:

    SELECT *,
        SUM(Input + Output) OVER(PARTITION BY ID ORDER BY Date) AS Total
    FROM table_a
    
    0 讨论(0)
  • 2020-12-21 19:51

    Use SUM() OVER(..) window function which produce cumulative sum :

    SELECT t.id,t.date,t.input,t.output,
           SUM(t.output+t.input) OVER(PARTITION BY t.ID ORDER BY t.date) as Total
    FROM YourTable t
    
    0 讨论(0)
提交回复
热议问题