Subquery in FROM (derived table)
SQL
Easy
3 views
Problem Description
Get department-wise average salary, then list departments where avg salary > 50000.
Sample Test Case
Input:
Employees, Departments
Official Solution
SELECT d.dept_name, t.avg_sal FROM (SELECT dept_id, AVG(salary) AS avg_sal FROM Employees GROUP BY dept_id) t JOIN Departments d ON d.dept_id = t.dept_id WHERE t.avg_sal > 50000;
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!