-- Group by job_id and then by manager_id
Select job_id, manager_id, sum (salary), count (*) from employees group by job_id, manager_id;
-- Group job_id first, output the result of status grouping, group by job_id, group by job_id, and group the grouped job_id by manager_id to output the result;
-- Output the sum of statistics in the first row (1 = 2 + 3 = 4 + 5 + 6 + 7 + 8 + 9 ). That is, the same result set is output twice according to different grouping conditions.
Select job_id, manager_id, sum (salary), count (*) from employees group by rollup (job_id, manager_id );
-- Group by manager_id first, and output rows. Then, output rows are grouped by job_id. Then, output rows are grouped by job_id and manager_id. That is, in fact, the same result set is grouped and output three times according to three conditions respectively.
Select job_id, manager_id, sum (salary), count (*) from employees group by cube (job_id, manager_id );
-- It can be seen that this is equivalent to the first two groups of the CUBE. The third group (group by job_id and manager_id at the same time) and total rows are missing.
Select job_id, manager_id, sum (salary), count (*) from employees group by grouping sets (job_id, manager_id );
-- In fact, group by grouping sets can also output a total. You only need to add an empty pair of parentheses:
Select job_id, manager_id, sum (salary), count (*) from employees group by grouping sets (job_id, manager_id ,());