Total Oracle sum

Source: Internet
Author: User

// Add the values of a column in the current row to the values of the column in the previous row, that is, the sum of the total values:
With t (
Select 1 val from dual union all
Select 3 from dual union all
Select 5 from dual union all
Select 7 from dual union all
Select 9 from dual)
Select val,
Sum (val)
Over (order by rownum rows between unbounded preceding and current row)
Sum_val
From t
Group by rownum, val
Order by rownum;
VAL SUM_VAL
--------------------
1 1
3 4
5 9
7 16
9 25
// Resolution:
// Sum (val) calculates the sum;
// Order by rownum sorts query records by pseudo-column rownum;
// Between unbounded preceding and current row: defines the start and end points of the window;
// Unbounded preceding: the start point of the window includes all rows read;
// Current row: The end of the window is the current row. The default value can be omitted;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.