AlgoMaster Logo

Exercise: String and Conditional Aggregation

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 a single comma-separated list of distinct artist countries from the artists table, ordered alphabetically. Exclude NULL countries.

SQL

Expected Query

Expected Output

Exercise 2

Easy

Write a query that returns the total amount of completed payments and the total amount of failed payments as two separate columns.

SQL

Expected Query

Expected Output

Exercise 3

Medium

Write a query that returns each album's title, the count of tracks, and a comma-separated list of track titles ordered by track_number. Order results by album title.

SQL

Expected Query

Expected Output

Exercise 4

Hard

Write a query that produces one row per album showing the album title, artist name, track count, total duration in seconds, and a comma-separated track listing ordered by track_number. Order results by album title.

SQL

Expected Query

Expected Output