Last Updated: May 10, 2026
For this exercise, we will work with below data:
Return all distinct countries from the users table. Exclude NULLs and order alphabetically.
Count how many distinct tracks have been streamed at least once. Use the streams table. Return a single value aliased as distinct_tracks.
Return all unique (country, verified) pairs from the artists table. Order by country, then verified.
Return all distinct countries that appear in the streams table for streams started on or after 2024-03-03. Order alphabetically.
Count how many distinct users have streamed in each country. Return one row per country with country and the count aliased as unique_users. Use the streams table. Order by unique_users descending, then country ascending. Exclude NULL countries.
Use DISTINCT ON to return the most recent stream per user along with the country of that stream. Show user_id, country, track_id, and started_at. Order the final result by user_id.