Interview Questions/SQL/Employee Salary Stats per Department

Employee Salary Stats per Department

Preview mode. Log in to edit, run, submit, and save progress.

Medium

Description

You are given a table of employees. Each employee has a name, a department, a salary, and a hire date. Write a SQL query to find for each department: the number of employees, the average salary (rounded to 2 decimal places), the maximum salary, and the minimum salary. Return the result ordered by department name. Table: Employees

Column NameTypeDescription
idINTPrimary key
nameVARCHAREmployee name
departmentVARCHARDepartment name
salaryINTAnnual salary
hire_dateDATEDate of hire

Database Schema (Inferred)

Employees

Column NameExample Value
id1
nameAlice
departmentEngineering
salary90000
hire_date2020-01-10

Example

Employees

idnamedepartmentsalaryhire_date
1AliceEngineering900002020-01-10
2BobEngineering850002019-06-15
3CarolMarketing700002021-03-01
4DaveMarketing650002022-07-20
5EveHR600002023-01-05

Output

departmentemployee_countavg_salarymax_salarymin_salary
Engineering2875009000085000
HR1600006000060000
Marketing2675007000065000

Explanation:

Group by department. Count employees, compute AVG/MAX/MIN of salary, and round AVG to 2 decimal places.

Approach hint

Start with a simple approach, explain the trade-off, then move toward a cleaner or more scalable solution.

Common mistake

Skipping assumptions, edge cases, or trade-offs can make an otherwise good answer feel incomplete.

SQL Editor
Loading...

Employees

idnamedepartmentsalaryhire_date
1AliceEngineering900002020-01-10
2BobEngineering850002019-06-15
3CarolMarketing700002021-03-01
4DaveMarketing650002022-07-20
5EveHR600002023-01-05

Output

departmentemployee_countavg_salarymax_salarymin_salary
Engineering2875009000085000
HR1600006000060000
Marketing2675007000065000