Browse and solve 1,200+ machine learning coding challenges on Deep-ML. Filter by difficulty (beginner, intermediate, advanced) and category (linear algebra, machine learning, deep learning, NLP, computer vision). Write Python solutions in the browser and get instant feedback against test cases.
You are given an employees table containing each employee's id, name, department, and salary. Write a single query that returns the employees whose salary is strictly greater than the average salary of the department they belong to. Return the columns id, name, department, and salary. Order the result by id in ascending order.
Employees in 'engineering': alice 90000, bob 60000, carol 75000 (avg = 75000); 'sales': dave 50000, erin 70000, frank 50000 (avg = ~56667); 'marketing': grace 80000 (avg = 80000).
id | name | department | salary 1 | alice | engineering | 90000 5 | erin | sales | 70000
For engineering the average is 75000, so only alice (90000) exceeds it; carol equals the average and is excluded. For sales the average is about 56667, so only erin (70000) exceeds it. For marketing grace equals her own department average (she is the only member), so she is excluded. The result, ordered by id, is alice and erin.