Oracle:grouping and Rollup

Source: Internet
Author: User

Oracle Grouping and rollup simple testing

Sql> SelectDEPARTMENT_ID,sum(Salary) fromEmployeeswheredepartment_idinch(Ten, -, -, -) GROUP by department_id Order  bydepartment_id;department_idSUM(SALARY)------------- -----------           Ten        4400            -       24900            -       58000           -       51608SQL> SelectDepartment_id,first_name,sum(Salary) fromEmployeeswheredepartment_idinch(Ten, -, -, -)Group by(Department_id,first_name) Order  bydepartment_id;department_id first_nameSUM(SALARY)------------- -------------------- -----------           TenJennifer4400            -Alexander3100            -Den11000            -Guy2600            -Karen2500            -Shelli2900            -Sigal2800            -Lex17000            -Neena17000            -Steven24000           -Daniel9000           -Ismael7700           -John8200           -Jose Manuel7800           -Luis6900           -Nancy12008 -rows Selectedsql> SelectDepartment_id,first_name,sum(Salary) fromEmployeeswheredepartment_idinch(Ten, -, -, -)GROUP BY rollup (Department_id,first_name) Order  bydepartment_id;department_id first_nameSUM(SALARY)------------- -------------------- -----------           TenJennifer4400           Ten                             4400            -Alexander3100            -Den11000            -Guy2600            -Karen2500            -Shelli2900            -Sigal2800            -                            24900            -Lex17000            -Neena17000            -Steven24000            -                            58000           -Daniel9000           -Ismael7700           -John8200           -Jose Manuel7800           -Luis6900           -Nancy12008           -                            51608department_id first_nameSUM(SALARY)------------- -------------------- -----------                                        138908 +rows Selectedsql> SelectDEPARTMENT_ID,grouping (department_id), first_name,grouping (first_name),sum(Salary) fromEmployeeswheredepartment_idinch(Ten, -, -, -)GROUP BY rollup (Department_id,first_name) Order  bydepartment_id;department_idGROUPING(department_id) First_NameGROUPING(first_name)SUM(SALARY)------------- ----------------------- -------------------- -------------------- -----------           Ten                       0Jennifer0        4400           Ten                       0                                         1        4400            -                       0Alexander0        3100            -                       0Den0       11000            -                       0Guy0        2600            -                       0Karen0        2500            -                       0Shelli0        2900            -                       0Sigal0        2800            -                       0                                         1       24900            -                       0Lex0       17000            -                       0Neena0       17000            -                       0Steven0       24000            -                       0                                         1       58000           -                       0Daniel0        9000           -                       0Ismael0        7700           -                       0John0        8200           -                       0Jose Manuel0        7800           -                       0Luis0        6900           -                       0Nancy0       12008           -                       0                                         1       51608department_idGROUPING(department_id) First_NameGROUPING(first_name)SUM(SALARY)------------- ----------------------- -------------------- -------------------- -----------                                    1                                         1      138908 +Rows selected

Rollup for subtotal and by group statistics.
Grouping (department_id) and Grouping (first_name)
If the current column is in an empty behavior, it is displayed as 1, not empty, and is displayed as 0;

Oracle:grouping and Rollup

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.