AlgoMaster Logo

Exercise: Median and Percentile Calculations

Last Updated: May 12, 2026

1 min read

For this exercise, we will work with below data:

SQL

Exercise 1

Easy

Write a query that returns both the continuous and the discrete median of track duration_seconds side by side.

SQL

Expected Query

Expected Output

Exercise 2

Easy

Write a query that returns the 25th, 50th, 75th, and 90th percentiles of track duration_seconds.

SQL

Expected Query

Expected Output

Exercise 3

Medium

Write a query that returns the median track duration per genre using PERCENTILE_CONT. Show the genretrack_count, and median_duration. Order alphabetically by genre.

SQL

Expected Query

Expected Output

Exercise 4

Medium

Write a query that returns the median duration_listened for each user using PERCENTILE_CONT. Show username and median_listen rounded to 1 decimal. Order alphabetically by username.

SQL

Expected Query

Expected Output

Exercise 5

Medium

Write a query that returns the global mean and median of payment amount for completed payments side by side, both rounded to 2 decimals.

SQL

Expected Query

Expected Output

Exercise 6

Hard

Write a query that returns the median total streams per user (counting all streams across all days). Use PERCENTILE_CONT on the per-user totals.

SQL

Expected Query

Expected Output