Example 1
Find employees who earn above the company average
The inner query computes the average salary (72500). The outer query then filters to only the rows where salary exceeds that value. Alice (70000) and Bob (50000) fall below the average and are excluded.
Source table data Rows loaded before the example query runs.
Setup
CREATE TABLE employees (id INT, name VARCHAR(50), salary INT);
INSERT INTO
employees (id, name, salary)
VALUES
(1, 'Alice', 70000),
(2, 'Bob', 50000),
(3, 'Carol', 90000),
(4, 'Dave', 80000);Validated query Shared across supported engines.
SQL
SELECT
name,
salary
FROM
employees
WHERE
salary > (
SELECT
AVG(salary)
FROM
employees
)
ORDER BY
salary DESC;Expected result Returned rows for the shared example.
| name | salary |
|---|---|
| Carol | 90000 |
| Dave | 80000 |
Output is identical across all engines.