Exercise 1
intermediateQuestion
Find employees who earn more than the average salary.
Table Schema
CREATE TABLE employees (
id INT PRIMARY KEY,
name VARCHAR(100),
salary DECIMAL(10,2)
);Show Solution
Solution
1SELECT name, salary
2FROM employees
3WHERE salary > (SELECT AVG(salary) FROM employees);Expected Output
| name | salary | |---|---| | Alice | 75000 | | Bob | 80000 |
Explanation
A scalar subquery returns a single value and can be used with comparison operators in WHERE clause.