Scalar Subquery: Employees Earning Above Company Average

Basics
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_idnamesalary
1Alice80
2Bob100
3Carol120
4Dan140

Expected Output

emp_idnamesalary
3Carol120
4Dan140

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 BY order is checked by the grader.
  • Query type: Write a single read-only Standard SQL SELECT (or WITH ... SELECT) query.

Constraints & Evaluation Criteria

  • Return `emp_id, name, salary` ordered by `emp_id ASC`.

Hints

SQL
Loading Code Editor...
+1 Hidden Submit Case
Input / Scenario
employees (4 rows)
Expected Output / Criteria
2 row(s): (3, Carol, 120); (4, Dan, 140)