SQL QuestSQL Interview Questions › Subqueries & CTEs

Below Department Average

MediumFreeQuerying BasicsSubqueries & CTEsAggregation & Grouping

Google's compensation team runs a quarterly pay-equity scan: flag employees whose salary is below their own department's average. Show name, department, salary, and dept_avg_salary (rounded to nearest dollar). Order by department ascending, then salary ascending, then name ascending as a tie-breaker. The correlated-subquery pattern here is a core Google analyst interview test — it reveals whether you can write SQL that references the outer row from inside a subquery, which is the mental model most candidates trip on.

Solve it in the browser editor →

Runs on SQLite in your browser, graded against the expected result, no signup. A wrong answer gets a diagnosis, not just "incorrect".

Schema

employees

emp_idnamedepartmentpositionsalaryhire_datemanager_idperformance_rating
1Alice JohnsonEngineeringSenior Developer950002019-03-1554.5
2Bob SmithEngineeringDeveloper750002020-06-0113.8
3Carol WilliamsMarketingMarketing Manager850002018-09-20NULL4.2

Expected output: Employees paid below their department average

Hint

Use a correlated scalar subquery: WHERE salary < (SELECT AVG(salary) FROM employees e2 WHERE e2.department = e.department). Show the dept avg with a second correlated subquery in SELECT

Concepts

SELECT Subquery WHERE Aggregation

Practise the topic: SQL practice questions · CTE practice · GROUP BY exercises

In these company practice sets

Airbnb · Databricks · Google · Ramp · Snowflake · Goldman Sachs

A SQL Quest challenge matched to patterns reported for these companies — not a question any of them has published.

Related questions

Department Roster with GROUP_CONCATMedium · FreeConsistent Director AnalysisMedium · FreeHighest Total Salary Budget DepartmentMedium · FreeFare Imputation AnalysisMedium · FreeUNION ALL Dedup: Cross-Dataset SearchMedium · FreeAbove-Average Departments (Derived Table)Medium · Free

Where would this cost you points in an interview?

Ten questions, no signup: a Skillmap across nine SQL skills and the one to fix first.

Take the readiness test