AlgoMaster Logo

Exercise: Date and Time Mastery

Last Updated: May 10, 2026

1 min read

For this exercise, we will work with below data:

SQL

Exercise 1

Easy

Extract the year from each album's release_date in the albums table. Show title and release_year. Order by release_year, then title.

SQL

Expected Query

Expected Output

Exercise 2

Easy

Compute each user's account age in days as of 2025-01-01. Use the users table. Show username and days_active, ordered by days_active descending.

SQL

Expected Query

Expected Output

Exercise 3

Medium

Count the streams that occurred in the first quarter of 2024 (January, February, March). Return a single row with q1_streams.

SQL

Expected Query

Expected Output

Exercise 4

Medium

Find subscriptions that lasted at least 350 days. Use the subscriptions table; treat NULL end_date as still active by using 2025-01-01 as the cutoff. Return subscription_iduser_id, and days_active, ordered by days_active descending.

SQL

Expected Query

Expected Output

Exercise 5

Medium

 For each campaign in the campaigns table, compute its planned duration in days. For campaigns with no end_date, treat the duration as the difference between 2025-01-01 and start_date. Show namestart_dateend_date, and duration_days. Order by name.

SQL

Expected Query

Expected Output