SQL from Zero › Module 8: Final project

Project: the bookshop business report

Answer the owner's real questions about sales, best sellers and reviews.

Lesson 33 of 33 · about 30 minutes

Video: From data to decisionsThe narrated video for this lesson is coming soon. The lesson below covers the same ideas.

The lesson

The bookshop's owner has a meeting with investors and needs answers. You have everything you need to give them.

This lesson's database is the bookshop plus two more tables:

reviews: id, book_id, customer_id, rating (1 to 5), comment. It holds seven reviews.

order_items: which books were in each order.

ColumnMeaning
order_idthe order (links to orders.id)
book_idthe book (links to books.id)
quantityhow many copies
pricethe price per copy when it was bought

An order can contain several books, so order_items can have several rows for the same order. The money from one row is quantity * price.

A word on cancelled orders. Order 3 was cancelled, so it shouldn't count as a sale. Join to orders and filter on its status.

Tips for report queries

  • Write the FROM and JOIN lines first, run them, and look at the rows. Then add WHERE, GROUP BY and the columns.
  • Money sums can show long decimals like 119.41000000000001. Use ROUND(..., 2), as the questions ask.
  • Give result columns clear names with AS. The owner will thank you.

These questions are deliberately like the ones real analysts get every day. Take your time, and use Hint whenever you need it.

Key ideas
  • Build big queries in small steps: joins first, then filters, then grouping.
  • Leave out cancelled orders when counting sales.
  • ROUND money to 2 decimal places and name columns clearly.

Practise

Loading practice…

Quick check

1. Why join order_items to orders when adding up sales?

2. Which filters groups, like books with at least 2 reviews?

3. You've finished SQL from Zero. Which order does a query run in, inside the engine?