6. Summarising and Grouping: Step 8

Demo

The 'HAVING' clause.

We can restrict the GROUPS included with the HAVING clause: to limit the groups to those where the number of employees is greater than 1:

SQL

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

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
SALESMAN 4 1400 1250.00 1600.00

Progress

Proceed to Next step