How to use Having in a query

Example

Employees table

IDMANAGER_IDSALDEPT_ID
183000I
283000I
31800I
47950I
521100I
691300I
7102850I
8102975I
9102450I
10NULL5000I

Count the number of employees greater than two and group by department

SELECT COUNT(ID) EMP_NO, DEPT_ID
FROM EMPLOYEES
WHERE MANAGER_ID IS NOT NULL
GROUP BY DEPT_ID
HAVING COUNT(ID) > 2;

Results

EMP_NODEPT_ID
520

Select the salary with having

SELECT ID, SAL
FROM EMPLOYEES
GROUP BY ID, SAL
HAVING SUM(SAL) >= 3000;

Results

IDSAL
13000.00
23000.00
105000.00