SELECT department_ID, count(employee_id) as '# of Employees' FROM EMPLOYEES
WHERE DEPARTMENT_ID IN
(
SELECT DEPARTMENT_ID
FROM EMPLOYEES
GROUP BY DEPARTMENT_ID
HAVING COUNT(*)>5
)
AND HIRE_DATE NOT LIKE '%JAN%'
group by department_ID;
このクエリはdepartment_idを返し、department_idでグループ化するため、各部門に属する従業員の数が返されます
出力は次のようになります
Department_Id | # of Employees
1 7
2 6
4 9