How to use and distinguish between cube and rollup sentences in Oracle GROUP by

Source: Internet
Author: User

The difference between rollup and cube in Oracle GROUP by:
Oracle's GROUP BY statement supports rollup and cube statements in addition to the most basic syntax.

In the case of rollup (a, B, c), group by IS performed on (a, B, c), then group by (A, B), then (a) group by, and finally group by operations on the whole table;

In the case of group by CUBE (A, B, c), the group by IS first performed (A, B, C), followed by (A, B), (A, C), (a), (b, C), (b), (c), and finally the group by operation of the whole table.

Test data:
/*
Oracle's GROUP BY statement supports rollup and cube statements in addition to the most basic syntax.
*/
--Create a table

Create Table fzq (     varchar     ),varchar(2),     Kemu   varchar (4),      varchar (3)     
Test Table

--Inserting data

Insert  intoFzqValues (' One','1','Mathematics',' -');Insert  intoFzqValues (' One','1','language',' the'); Insert  intoFzqValues (' A','1','Mathematics',' -'); Insert  intoFzqValues (' A','1','language',' the'); Insert  intoFzqValues (' A','2','Mathematics',' -'); Insert  intoFzqValues (' A','2','language',' the'); Insert  intoFzqValues (' -','2','Mathematics',' the'); Insert  intoFzqValues (' -','2','language','98');Commit;
test Data
    • SELECT * from Fzq;

    • Select Calss,name,sum (Chengji) from FZQ Group by Calss,name;

    • Select Calss,name,sum (Chengji) from FZQ Group by Cube (calss,name) order by CALSS;

    • Select Calss,name,sum (Chengji) from FZQ GROUP by rollup (calss,name) Order by CALSS;

    • Select Calss,name,sum (Chengji) from FZQ Group by grouping sets (Calss,name);

How to use and distinguish between cube and rollup sentences in Oracle GROUP by

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.