AlgoMaster Logo

Exercise: CROSS JOIN

Last Updated: May 12, 2026

1 min read

For this exercise, we will work with below data:

SQL

Exercise 1

Easy

Using CROSS JOIN, produce every combination of artist (artist name) and genre (genre name). Order by artist, then genre.

SQL

Expected Query

Expected Output

Exercise 2

Easy

Using CROSS JOIN, list every artist paired with every distinct user country from users. Show artist and country. Order by artist, then country.

SQL

Expected Query

Expected Output

Exercise 3

Medium

Using CROSS JOIN, build a grid of every (user, genre) pair and the user's stream count in that genre. Include zero-count cells. Show usernamegenrestreams_in_genre. Order by username, then genre.

SQL

Expected Query

Expected Output

Exercise 4

Hard

Build a date-spine query that shows, for each day from 2024-03-01 to 2024-03-04, the cumulative count of streams up to and including that day. Use generate_series plus CROSS JOIN with streams, then filter in the ON or WHERE. Show day and cumulative_streams. Order by day.

SQL

Expected Query

Expected Output