AnalystPath

Courses Booked Heavily in Two Consecutive Years

SQLMediumMid level~15 min

Problem

An online learning platform records course enrolments. Table `bookings` has `(booking_id, course_id, seats, booked_on)` where `booked_on` is a date.

Find the `course_id` of every course that was booked four or more times (four or more booking rows) within a single calendar year in each of two consecutive years. In other words, there exists some year Y such that the course has at least 4 bookings in year Y and at least 4 bookings in year Y+1.

Return the result in any order.

Tables

Example rows — the live problem includes the full dataset.

bookings
booking_idcourse_idseatsbooked_on
110012021-01-10
210012021-03-10
310012021-06-10

Expected output

Your answer should return 1 row with the columns course_id.

Starter code (SQL)

SELECT *
FROM bookings;

Solve this SQL question free

Write SQL and run it instantly in your browser — even on your phone. No signup needed to try.

Solution & explanation

Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.

Sign up free to unlock

Related SQL questions