AnalystPath

Apply Publisher Promotions to Book Prices

SQLMediumMid level~15 min

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.

books
book_idpublisherlist_price
1Lantern Press1000
2Cedar House50
3Lantern Press1200
promotions
publisherpercentage_off
Lantern Press10
Cedar House20

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

Related SQL questions