SQL QuestSQL Interview Questions › Window Functions

Median Salary Without PERCENTILE

HardProQuerying BasicsWindow FunctionsAggregation & GroupingSubqueries & CTEs

Calculate the median salary across all employees without using a built-in PERCENTILE or MEDIAN function. Show a single value: median_salary. If the count is odd, return the middle value. If even, return the average of the two middle values, rounded to 2 decimals. Google asks this pattern frequently because it tests understanding of row ordering and positional logic.

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: median_salary: 70000

Hint

This is a Pro challenge — the hint, the step-by-step tutor and the reference solution open in the app.

Concepts

SELECT Window Functions ROW_NUMBER COUNT Subquery CTE Window Functions + Subquery

Practise the topic: SQL practice questions · Window function practice · GROUP BY exercises · CTE practice · Ranking function practice · Advanced SQL interview questions

In these company practice sets

Anthropic · Google · Meta · NVIDIA · Snowflake

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

Related questions

Cumulative Distinct Customers Over TimeHard · FreeSalary Rank Within DepartmentHard · FreeRunning Total RevenueHard · FreeYear-over-Year GrowthHard · Free7-Day Rolling Revenue AverageHard · FreeMulti-CTE Revenue PipelineHard · 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