AlgoMaster Logo

Exercise: Overlap Detection and Date Ranges

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 lists every campaign whose date range overlaps with the date range 2024-03-15 to 2024-04-30 (inclusive). Show campaign_idnamechannelstart_date, and end_date. Order by campaign_id.

SQL

Expected Query

Expected Output

Exercise 2

Easy

Write a query that returns every subscription whose date range covers the date 2023-07-01 (inclusive). Treat NULL end_date as an open-ended interval. Show subscription_iduser_idstart_date, and end_date. Order by subscription_id.

SQL

Expected Query

Expected Output

Exercise 3

Easy

 Write a query that returns every subscription whose date range overlaps with the date range 2022-01-01 to 2022-12-31 (the year 2022). Show subscription_iduser_idstart_date, and end_date. Order by subscription_id.

SQL

Expected Query

Expected Output

Exercise 4

Medium

Write a query that returns every campaign that does NOT overlap with any other campaign on the same channel. Show campaign_idnamechannelstart_date, and end_date. Order by campaign_id.

SQL

Expected Query

Expected Output