Ivy Professional School
Rating
Learning/SQL Data Drill #1

Department Payroll

Last updated

Practice SQL JOINs and aggregate functions by calculating the total salary expenditure for each department in a company.

SQLBeginnerINNER JOINGROUP BYSUM

Your Objective

Practice SQL JOINs and aggregate functions by calculating the total salary expenditure for each department in a company.

The Setup

Your dataset contains two tables from a company's HR database: 1. A Department table with the ID and name of each department 2. An Employee table with the ID, name, salary, joining date, and department reference for each employee

Table Schema

Department
ColumnTypeKey / Notes
idINTPK
nameVARCHAR(50)
Employee
ColumnTypeKey / Notes
idINTPK
nameVARCHAR(50)
salaryDECIMAL(10,2)
joining_dateDATE
department_idINTFK

Sample Data

Department — 8 rows

idname
1HR
2Engineering
3Marketing
4Sales
5IT
6Finance
7Graphic Designer
8Data Analyst

Employee — 20 rows

idnamesalaryjoining_datedepartment_id
1Alice70,0002020-01-151
2Bob85,0002019-03-222
3Charlie60,0002021-05-181
4David95,0002018-07-113
5Eva80,0002017-09-092
6Frank75,0002016-11-143
7Grace90,0002015-02-231
8Henry68,0002021-04-302
9Irene72,0002020-06-251
10Jack78,0002019-08-193
11Karen83,0002018-10-074
12Leo95,0002017-12-131
13Mona87,0002016-03-212
14Nick63,0002015-05-295
15Olivia77,0002014-07-151
16Peter82,0002021-01-182
17Quinn91,0002020-03-126
18Rachel88,0002019-09-281
19Steve93,0002018-11-062
20Tina76,0002017-04-163

Your Task

Find the total salary for each department. Your result table should have department_name and total_salary columns.

Your output should look like this (partial example):

department_nametotal_salary
HR552,000
Engineering495,000
……
Explore Enterprise Solutions