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 Name | Type | Description |
|---|---|---|
| id | INT | Primary key |
| name | VARCHAR | Employee name |
| department | VARCHAR | Department name |
| salary | INT | Annual salary |
| hire_date | DATE | Date 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