6. Summarising and Grouping: Step 6

Demo

Summarise groups of data.

If we want the analysis of salary by job, it would be useful to be able to do all jobs at once. The GROUP clause serves this function.

SQL

SELECT job, count(*), round(avg(sal)), min(sal), max(sal) FROM emp GROUP BY job;

Output

job count(*) round(avg(sal)) min(sal) max(sal)
ANALYST 2 3000 3000.00 3000.00
CLERK 4 1038 800.00 1300.00
MANAGER 3 2758 2450.00 2975.00
PRESIDENT 1 5000 5000.00 5000.00
SALESMAN 4 1400 1250.00 1600.00

Progress

Proceed to Next step