E-commerce: Units Ordered Last Week
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 an SQL query that determines how many units were ordered from Amazon's e-commerce platform in the last week. Your output should have the following columns: item_category, total_units_ordered_last_7_days
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 Yesterday (1 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
SELECT i.item_category, SUM(o.order_quantity) AS total_units_ordered_last_7_days
FROM orders o
JOIN items i ON o.item_id = i.item_id
WHERE o.order_date BETWEEN date('now', '-6 days') AND date('now')
GROUP BY i.item_category;
Can someone explain to me the difference between:
WHERE order_date > current_date - interval '7 days'andWHERE order_date BETWEEN CURRENT_DATE - INTERVAL '6 days' AND CURRENT_DATEBoth give the same result in PostrgreSQL, but only the second one passes the test cases.