Unpopular Books

4pts
Amazon

Problem Statement

Amazon wants to clear out stock of unpopular books. Write an SQL query to find books that have sold less than 10 copies in the last year (from 2025-02-09 to 2026-02-09).

Rules:

  • Exclude books that were released in the last month (on or after 2026-01-09).
  • Include books that had zero sales in the last year.
  • Output columns: book_id, name.
  • Results must be sorted by book_id in ascending order.
Tests your understanding of
Date Manipulation, Joins and Aggregation

Input Tables

Books
book_id(INTEGER)name(VARCHAR)available_from(DATE)
1SQL Basics2020-01-01
2Advanced Python2021-05-10
3Data Science Pro2026-01-20
4Legacy Code2015-12-01
Orders
order_id(INTEGER)book_id(INTEGER)quantity(INTEGER)dispatch_date(DATE)
101152025-12-01
102162025-06-01
Inventory_Status
book_id(INTEGER)warehouse_id(INTEGER)
1501

Expected Output

book_id(INTEGER)name(VARCHAR)
2Advanced Python
4Legacy Code

Tags

MediumDate ManipulationJoinsAggregation
20-25 min
48%

Hints