Sum over usage, and difference with group

Source: Internet
Author: User

1. sum over usage

Sum (col1) over (partition by col2 order by col3)

The above function can be understood as: grouping by col2 (partition), sorting by col3 (Order), and continuous addition (SUM)

Table A has the following content:
B c d
02 02 1
02 03 2
02 04 3
02 05 4
02 01 5
02 06 6
02 07 7
02 03 5
02 02 12
02 01 2
02 01 23

Run: Select B, c, d, sum (d) over (partition by B, C order by D) E from

Expected result:

B c e
02 01 2
02 01 7
02 01 30
02 02 1
02 02 13
02 03 2
02 03 7
02 04 3
02 05 4
02 06 6
02 07 7

We can see that the values of column E are accumulate and.


2. Differences from group

Same Table A: Select B, c, sum (d) e from a group by B, c

B c e
02 01 30
02 02 13
02 03 7
02 04 3
02 05 4
02 06 6
02 07 7

The difference is obvious.

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.