Senior
The company LLC "Romashka" is represented by the tables employee(id, department_id, name, salary) and department (id, name). List the departments where the difference between the maximum and minimum employee salaries is more than 50 thousand.
sobes.tech AI
Answer from AI
To solve the task, you need to execute an SQL query that calculates, for each department, the difference between the maximum and minimum employee salaries, and then filters departments where this difference exceeds 50,000.
Example query:
SELECT d.name AS department_name,
MAX(e.salary) - MIN(e.salary) AS salary_diff
FROM department d
JOIN employee e ON d.id = e.department_id
GROUP BY d.id, d.name
HAVING MAX(e.salary) - MIN(e.salary) > 50000;
This query:
- joins the department and employee tables on department_id;
- groups data by departments;
- calculates the difference between the maximum and minimum salaries in each department;
- displays only those departments where this difference exceeds 50,000.