Super aggregation group in Oracle grouping statement

Source: Internet
Author: User

In Oracle, we may prefer to use the group by clause, but many people may not know that in the group by clause, we can perform super aggregate group search. At this time, we use two keywords, A rollup and a cube.

Rollup is grouped from right to left based on the group by condition. That is to say, if two group by conditions exist, the group by operation is performed once based on only one condition on the right, then, group by is performed based on the two conditions on the right.

Cube is more comprehensive. In addition to grouping from the right to the left, it will be further grouped from the left to the right. Therefore, there will be more result sets after cube. The two grouping syntaxes are as follows.

Select
Col1,
Col2,
Sum (Col3)
From
TBL
Group   By Rollup (col1, col2)

 

 

Select
Col1,
Col2,
Sum (Col3)
From
TBL
Group   By Cube (col1, col2)

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.