Back to Practice
#0366

Median Value for Odd Row Count

HardSQL35 min25 XP

Problem

Return the median salary when the table has an odd number of rows.

Why This Matters

SQL interviews usually test whether you can turn a business question into the right rows, grouping level, join type, and edge-case behavior.

Schema

employees(employee_id INTEGER, salary INTEGER)

Examples

Example 1
Inputsalaries 50, 100, 200
Output100

For three rows, the median is row 2 after sorting.

Constraints

  • Return only the requested columns.
  • Use deterministic ORDER BY when multiple rows are returned.
  • Assume SQLite-compatible SQL unless the prompt states otherwise.
CodeSQL
Visible browser tests run here when available.
Testcases1 visible / 3 hidden categories
Core SQL case
Inputsalaries 50, 100, 200
Expected[[100]]

For three rows, the median is row 2 after sorting.

Hidden Test Categories
Empty or missing matchesDuplicate rows or tiesNULL values where the pattern commonly breaks