BasicsSubqueryAVGGoogleAmazonMeta
Table
employees(emp_id INT, name VARCHAR, salary INT)
Task
From employees(emp_id, name, salary), return emp_id, name, salary for employees earning strictly more than the company-wide average salary, ordered by emp_id ASC.
Why It Matters: Scalar subqueries (WHERE salary > (SELECT AVG(salary) FROM ...)) let you compare individual rows against table-wide benchmarks in one query.
Output columns: emp_id, name, salary
Example
Input — employees
| emp_id | name | salary |
|---|---|---|
| 1 | Alice | 80 |
| 2 | Bob | 100 |
| 3 | Carol | 120 |
| 4 | Dan | 140 |
Expected Output
| emp_id | name | salary |
|---|---|---|
| 3 | Carol | 120 |
| 4 | Dan | 140 |
Explanation: First computes the company-wide average salary in the subquery, then returns only employees strictly above that threshold.
Requirements
- Exact output columns:
emp_id,name,salary - Row order: Exact
ORDER BYorder is checked by the grader. - Query type: Write a single read-only Standard SQL
SELECT(orWITH ... SELECT) query.
Constraints & Evaluation Criteria
- Return `emp_id, name, salary` ordered by `emp_id ASC`.
Hints
SQL⌘/Ctrl+Enter to Run · ⌘/Ctrl+Shift+Enter to Submit
Loading Code Editor...
+1 Hidden Submit Case
Input / Scenario
employees (4 rows)
Expected Output / Criteria
2 row(s): (3, Carol, 120); (4, Dan, 140)