简体   繁体   中英

Name of the department that has largest number of employees

I have two tables:

Here you can see attributes of both tables

I have written a code that shows the number of employees each department has.

select department_id, count(employee_id) 
from employees
group by department_id
order by count(employee_id) desc 

(See the output)

I would like to know the way how to do it. I guess I need to join tables but still can't do it.

I use SQL Developer by Oracle

Thanks for your response!

Your query seems perfect. Are you trying to get department names along with department_id? Then you can join Department table.

  select e.department_id,d.department_name, count(e.employee_id) TotalEmployee from employees e 
          inner join departmnet d on e.department_id=d.department_id
   group by e.department_id
   order by count(e.employee_id) desc 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM