Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

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

Employee Model  Database - w3resource online SQLite practice

Structure of 'hr' database :

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?