Popular Titles Borrowed in a Month
Problem
Table: `Title`
```text
+------------+---------+
| Column | Type |
+------------+---------+
| title_id | int |
| title_name | varchar |
| shelf | varchar |
+------------+---------+
title_id is the primary key. Each row describes one library title.
```
Table: `Loan`
```text
+------------+---------+
| Column | Type |
+------------+---------+
| title_id | int |
| loaned_on | date |
| copies | int |
+------------+---------+
This table may contain duplicate title_id rows. Each row records how many
copies of a title were loaned out on a given day.
```
Find every title whose **total copies loaned during August 2020** is **at least 100**. Report `title_name` and the summed quantity under the column `copies`. Rows may be in any order.
**Example**
```text
Title:
+----------+----------------+--------+
| title_id | title_name | shelf |
+----------+----------------+--------+
| 1 | Atlas of Tides | A1 |
| 2 | Quiet Engines | B3 |
+----------+----------------+--------+
Loan:
+----------+------------+--------+
| title_id | loaned_on | copies |
+----------+------------+--------+
| 1 | 2020-08-03 | 60 |
| 1 | 2020-08-20 | 50 |
| 2 | 2020-08-09 | 40 |
| 2 | 2020-07-31 | 90 |
+----------+------------+--------+
Output:
+----------------+--------+
| title_name | copies |
+----------------+--------+
| Atlas of Tides | 110 |
+----------------+--------+
```
Atlas of Tides loaned 110 copies in August (≥ 100). Quiet Engines only loaned 40 in August (its 90 fall in July), so it is excluded.
Tables
Example rows — the live problem includes the full dataset.
| title_id | title_name | shelf |
|---|---|---|
| 1 | Atlas of Tides | A1 |
| 2 | Quiet Engines | B3 |
| title_id | loaned_on | copies |
|---|---|---|
| 1 | 2020-08-03 | 60 |
| 1 | 2020-08-20 | 50 |
| 2 | 2020-08-09 | 40 |
Expected output
Your answer should return 1 row with the columns title_name, copies.
Starter code (SQL)
SELECT *
FROM Title;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