ORACLE SQL: Show the department name, id, and # of employees of the dept. that has the least # of employees -


note, homework question!

show department number, department name, , number of employees working in department has least number of employees.

i can figure out how many employees each department has, how show department least number of employees?

select employees.department_id, departments.department_name, count(employee_id) employees join departments on employees.department_id = departments.department_id group employees.department_id, departments.department_name; 

what need having clause, allows apply condition after group by clause applied. in other words, allows apply condition on aggregate expression:

select employees.department_id, departments.department_name, count(employee_id) employees join departments on employees.department_id = departments.department_id group employees.department_id, departments.department_name; having count(*) > 5 -- here! 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -