← All Exercises
SQL Subqueries
intermediatesql
Background
Subqueries nest one query inside another, enabling complex filtering and computation based on query results.
Problem
Write a SQL query to find employees who earn more than the average salary of their department using a correlated subquery.
Input
An employees table with id, name, department, salary columns.
Output
Employees earning above their department average salary.
Sample tests
Sample 1
Input: employees across 3 departments with varying salaries
Expected: employees above their dept average
Your solution
Learning objective
Learn correlated subqueries, subquery in WHERE, and performance considerations.