AnalystPath

Quietly Rented Board Games

SQLMediumMid level~15 min

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
game_idtitleshelved_on
1Catacomb Quest2014-01-01
2River Trade2016-05-12
3Skyline Rails2023-06-10
rental
rental_idgame_idcopiesrented_on
1122022-07-26
2112022-11-05
3382023-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

Related SQL questions