diff --git a/Order and Deliver/# 1251. Average Selling Price.sql b/Order and Deliver/# 1251. Average Selling Price.sql index 5760a4e..feffb5c 100644 --- a/Order and Deliver/# 1251. Average Selling Price.sql +++ b/Order and Deliver/# 1251. Average Selling Price.sql @@ -4,7 +4,8 @@ # For each product_id there will be no two overlapping periods. That means there will be no two intersecting periods for the same product_id. SELECT p.product_id, ROUND(SUM(u.units*p.price)/SUM(u.units),2) AS average_price -FROM Prices p JOIN UnitsSold u USING(product_id) -WHERE u.purchase_date BETWEEN p.start_date AND p.end_date +FROM Prices p LEFT JOIN UnitsSold u +ON p.product_id = u.product_id +AND u.purchase_date BETWEEN p.start_date AND p.end_date GROUP BY 1 ;