Apply Publisher Promotions to Book Prices
Problem
An online bookstore runs promotions by publisher. Each book belongs to one publisher and has a list_price in whole shekels. A promotions table gives a percentage_off for some publishers. Compute the checkout_price for every book as list_price minus list_price * percentage_off / 100. Books whose publisher has no promotion keep their list_price unchanged. Return book_id, checkout_price and publisher, ordered by book_id.
Tables
Example rows — the live problem includes the full dataset.
| book_id | publisher | list_price |
|---|---|---|
| 1 | Lantern Press | 1000 |
| 2 | Cedar House | 50 |
| 3 | Lantern Press | 1200 |
| publisher | percentage_off |
|---|---|
| Lantern Press | 10 |
| Cedar House | 20 |
Expected output
Your answer should return 4 rows with the columns book_id, checkout_price, publisher.
Starter code (SQL)
SELECT *
FROM books;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