E-commerce: Units Ordered Yesterday
EasyPremium
Amazon is a large e-commerce platform where customers can order various items ranging from electronics to clothing.
You're provided with two tables, orders and items, with the following columns:
Write a SQL query that determines how many units were ordered on Amazon yesterday. Output it under the total_units_ordered_yesterday
This question is part of a 5-part e-commerce question series. The other lessons in the series are linked below:
- E-commerce: Units Ordered Last Week (2 of 5)
- E-commerce: Total Orders by Category (3 of 5)
- E-commerce: Earliest Order by Customer (4 of 5)
- E-commerce: Second Earliest Order (5 of 5)
-- SQLite (used by code editor)
SELECT SUM(o.order_quantity) AS total_units_ordered_yesterday
FROM orders o
WHERE o.order_date = date('now', '-1 day');
-- MySQL
SELECT SUM(o.order_quantity) AS total_units_ordered_yesterday
FROM orders o
WHERE o.order_date = DATE_SUB(CURDATE(), INTERVAL 1 DAY);
select sum(order_quantity) as total_units_ordered_yesterday from orders as ord join items as it on ord.item_id=it.item_id where order_date="2023-10-14"