Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion 4-multiple-tables/27_online_shop.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
-- Online Shop 🛍️
-- Codédex

-- No solution for this one yet! :)
-- Best selling items
SELECT products.name, products.price, COUNT(orders.item_id)
FROM orders
JOIN products ON orders.item_id = products.id
GROUP BY products.name
ORDER BY COUNT(orders.item_id) DESC;

-- All orders per customer
SELECT customers.name, orders.item_id, products.name
FROM orders
LEFT JOIN products ON orders.item_id = products.id
LEFT JOIN customers ON orders.customer_id = customers.id;

-- Highest sales days
SELECT date, SUM(price)
FROM orders
JOIN products ON orders.item_id = products.id
GROUP BY date
ORDER BY SUM(price) DESC;