Healthy Shop database
MULTIPLE JOINs – Exercises
9. Exercise 5 – Get to know the sales_history table

Instruction

Don't give up! Here comes the next table!

Exercise

This time we'll add information about the shop's daily sales.

The sales_history table consists of the following three columns:

  • product_id - the ID of a given product,
  • date - the date of sale, and
  • amount - the amount of a given product sold on a particular day.

For every day in the sales_history table show the sales of the products with ID's 13, 18, and 15.

Display the date, name, amount, and calorific value of a product.

Order the results by date and then by calorific value.

Stuck? Here's a hint!

Type:

SELECT
  date,
  p.name,
  amount,
  calories
FROM product p
JOIN sales_history sh
  ON p.id = sh.product_id
JOIN nutrition_data nd
  ON nd.product_id = p.id
WHERE p.id IN (13, 18, 15)
ORDER BY date, calories

Console

Code editor

Result

TableConsole