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

Employee Salary Stats per Department

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

Examples

Example 1

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.

query.sql