Created
August 14, 2019 05:45
-
-
Save sunyuding/5fcdab3edfabb6a41b7f651a49aa2616 to your computer and use it in GitHub Desktop.
Hacker Rank MySQL Employees by department excercise
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Hacker Rank MySQL Employees by department excercise | |
Write a query to print the respective Department Name and total of employees per department for all departments in Department table | |
Include departments with 0 employees. | |
Order the results per total of employees, if 2 or more departments have the same amount of employees then order alphabetically by department name | |
*/ | |
SELECT DEPARTMENT.NAME, COUNT(EMPLOYEE.ID) AS COUNT_OF_EMPLOYEES_IN_THE_DEPARTMENT | |
FROM DEPARMENT | |
LEFT JOIN EMPLOYEE ON DEPARTMENT.ID = EMPLOYEE.DEPT_ID | |
GROUP BY DEPARTMENT.NAME | |
ORDER BY COUNT_OF_EMPLOYEES_IN_THE_DEPARTMENT DESC, DEPARTMENT.NAME ASC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment