AlgoMaster Logo

Exercise: Nth Highest Value

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 the title and stream count of the track with the highest stream count, including all tracks tied at that count. Use DENSE_RANK. Order by title.

SQL

Expected Query

Expected Output

Exercise 2

Easy

Write a query that returns the 3rd longest track using LIMIT and OFFSET. Show title and duration_seconds. Return exactly one row.

SQL

Expected Query

Expected Output

Exercise 3

Medium

Write a query that returns every track tied at the 2nd highest stream count. Use a CTE with DENSE_RANK. Show title and stream_count. Order by title.

SQL

Expected Query

Expected Output

Exercise 4

Medium

Write a query that returns the user with the 3rd highest total listening time (sum of duration_listened). Use DENSE_RANK. Show username and total_listened.

SQL

Expected Query

Expected Output

Exercise 5

Hard

Write a query that returns the 2nd lowest distinct duration_seconds value among all tracks, including every track that matches it. Use DENSE_RANK ordered ascending. Show title and duration_seconds. Order by title.

SQL

Expected Query

Expected Output