Quietly Rented Board Games
Problem
A board game cafe lends out games and tracks every rental.
Table: game
+--------------+---------+
| Column Name | Type |
+--------------+---------+
| game_id | int |
| title | varchar |
| shelved_on | date |
+--------------+---------+
game_id is the primary key. shelved_on is the date the game first became available to rent.
Table: rental
+--------------+------+
| Column Name | Type |
+--------------+------+
| rental_id | int |
| game_id | int |
| copies | int |
| rented_on | date |
+--------------+------+
rental_id is the primary key. Each row records that some copies of a game were rented on a date.
Write a solution to report the games that were rented fewer than 10 copies in the last year, excluding any game that has been on the shelf for less than one month. Assume today is 2023-06-23, so 'last year' means rentals on or after 2022-06-23, and a game counts as too new if it was shelved on or after 2023-05-23. Return columns game_id and title in any order.
Tables
Example rows — the live problem includes the full dataset.
| game_id | title | shelved_on |
|---|---|---|
| 1 | Catacomb Quest | 2014-01-01 |
| 2 | River Trade | 2016-05-12 |
| 3 | Skyline Rails | 2023-06-10 |
| rental_id | game_id | copies | rented_on |
|---|---|---|---|
| 1 | 1 | 2 | 2022-07-26 |
| 2 | 1 | 1 | 2022-11-05 |
| 3 | 3 | 8 | 2023-06-11 |
Expected output
Your answer should return 3 rows with the columns game_id, title.
Starter code (SQL)
SELECT *
FROM game;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