employee department wise and count of employees more than 5

后端 未结 3 1047
我在风中等你
我在风中等你 2021-01-29 05:14

i want to display department_id\'s along with count,and count should be more than 5, and i want to have employees who are not hired in January.

i tried the

3条回答
  •  难免孤独
    2021-01-29 05:48

    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;
    

    This query returns the department_id and because I group by department_id, the count of employees that belong to each department will be returned

    Output will look something like this

      Department_Id | # of Employees
            1             7
            2             6
            4             9
    

提交回复
热议问题