SQLite Exercise: Get the department name and number of employees in the department
Write a query to get the department name and number of employees in the department.
Sample table: employees
Sample table: departments
SQLite Code:
SELECT depart_name AS 'Department Name',
COUNT(*) AS 'No of Employees'
FROM departments
INNER JOIN employees
ON employees.department_id = departments.department_id
GROUP BY departments.department_id, depart_name
ORDER BY depart_name;
Output:
Department Name No of Employees --------------- --------------- Accounting 2 Administration 1 Executive 3 Finance 6 Human Resources 1 IT 5 Marketing 2 Public Relation 1 Purchasing 6 Sales 34 Shipping 45
Practice SQLite Online
Model Database
Structure of 'hr' database :
Improve this sample solution and post your code through Disqus.
Previous: Write a query to find the names (first_name, last_name) and hire date of the employees who were hired after 'Jones'.
Next: Write a query to find the employee ID, job title number of days between ending date and starting date for all jobs in department 90 from job history.
What is the difficulty level of this exercise?
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework