Oraclerollup and cube Analysis

Source: Internet
Author: User
Tags dname
Rollup is an extension of groupby, which performs subtotal and total operations. cube contains rollup, which is a more fine-grained subtotal and total. When there is only one field, rollup and cube are the same. You can use grouping to test rollup and cube: 0; 1. If you do not read [view indicates that the column is displayed; if you do not read it, it indicates that the column is not displayed.] ① rollup (I) does not read anything. (ii) from

Rollup is an extension of group by, which performs subtotal and total operations. cube contains rollup, which is a more granular subtotal and total. When there is only one field, rollup and cube are the same. You can use grouping to test rollup and cube: 0; 1. If you do not read [view indicates that the column is displayed; if you do not read it, it indicates that the column is not displayed.] ① rollup (I) does not read anything. (ii) from

Rollup is an extension of group by, which performs subtotal and total operations. cube contains rollup, which is a more granular subtotal and total. When there is only one field, rollup and cube are the same.

You can use grouping to test rollup and cube: 0; 1. do not view [view indicates that the column is displayed; otherwise, it indicates that the column is not displayed]

① Rollup

(I) read nothing

(Ii) from left to right

-

Refer to the first 1st

│ Check the first two

Refer to the first three

② Cube: 0, 1 in full order

Rollup

The columns specified after rollup are separated by commas. The calculation result of rollup is related to the sequence of the columns specified after rollup, because the grouping of rollup is directional. If n columns are specified, n + 1 grouping method is available. You can change the column order to meet different business needs. Be sure to keep in mind the impact of column order on results!

Example:

1.20: 32: 51 scott @ ORCL (^ ω ^) select. dname, B. job, sum (B. sal) sum_sal, grouping (. dname), grouping (B. job)
2.20: 33: 06 2 from dept a, emp B
3.20: 33: 06 3 where a. deptno = B. deptno
4.20: 33: 06 4 group by rollup (a. dname, B. job)
5.20: 33: 08 5/
6.
7. dname job SUM_SAL GROUPING (A. DNAME) GROUPING (B. JOB)
8 .--------------------------------------------------------------
9. sales clerk 950 0 0
10. sales manager 2850 0 0
11. sales salesman 5600 0 0
12. SALES 9400 0 1
13. research clerk 1200 0 0
14. research analyst 7000 0 0
15. research manager 2975 0 0
16. RESEARCH 11175 0 1
17. accounting clerk 1300 0 0
18. accounting manager 2450 0 0
19. ACCOUNTING presiindent 5000 0 0
20. ACCOUNTING 8750 0 1
21. 29325 1 1
22.
23. You have selected 13 rows.
Explanation: Do not look at anything (); from left to right, first look at the first)

You can remove columns that do not require subtotal or aggregate from rollup, and leave the columns to be subtotal in rollup.

For example:

1.20: 48: 37 scott @ ORCL (^ ω ^) select. dname, B. job, sum (B. sal) sum_sal, grouping (. dname), grouping (B. job)
2.20: 57: 43 2 from dept a, emp B
3.20: 57: 43 3 where a. deptno = B. deptno
4.20: 57: 43 4 group by a. dname, rollup (B. job)
5.20: 57: 45 5/
6.
7. dname job SUM_SAL GROUPING (A. DNAME) GROUPING (B. JOB)
8 .----------------------------------------------------------------------------------------
9. sales clerk 950 0 0
10. sales manager 2850 0 0
11. sales salesman 5600 0 0
12. SALES 9400 0 1
13. research clerk 1200 0 0
14. research analyst 7000 0 0
15. research manager 2975 0 0
16. RESEARCH 11175 0 1
17. accounting clerk 1300 0 0
18. accounting manager 2450 0 0
19. ACCOUNTING presiindent 5000 0 0
20. ACCOUNTING 8750 0 1
21.
22. 12 rows have been selected.

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.