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