Oracle ROLLUP and CUBE usage

Source: Internet
Author: User

CUBE and ROLLUP are new SQL keywords since Oracle8i. 9i and-11G are not new. It is an extension of the GROUP BY clause, allows you to calculate the subtotal of different levels in the SELECT statement.

CUBE is another extension of the group by clause. It allows you to calculate all possible combinations of subtotal to generate various summary reports.

The following describes their usage

Select B, c, D from Atest group by rollup (B, C, D );

Equivalent

Select B, c, D from Atest group by B, C, D;

Union all

Select B, c, null from Atest group by B, C

Union all

Select B, null, null from Atest group by B

Select B, c from Atest group by cube (B, C );

Merge the group by subsets of all (B, C) Combinations

Equivalent

Select B, c from Atest group by B, C

Union all

Select B, null from Atest group by B

Union all

Select null, c from Atest group by c

Union all

Select null, null from Atest group by null

Related Article

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.