AlgoMaster Logo

Exercise: Pivot Patterns and Data Reshaping

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 pivots the users table to show counts of subscription_tier values per country, with one column for premium and one for free. Order by country.

SQL

Expected Query

Expected Output

Exercise 2

Medium

Write a query that pivots stream counts by country (rows) across janfebmar for Q1 2024. Order by country.

SQL

Expected Query

Expected Output

Exercise 3

Hard

Write a query that produces a stream-count pivot with rows per country and columns per genre (poprockelectronicjazz) for Q1 2024. Order by country.

SQL

Expected Query

Expected Output