From 825e48d62d8ac0e2ee87196e1de84619ffdef17c Mon Sep 17 00:00:00 2001 From: Varada MV <36720961+shinevarada@users.noreply.github.com> Date: Tue, 25 Jun 2024 17:20:48 +0000 Subject: [PATCH] Master Solution for #1251. Average Selling Price will not satisfy all the test cases in leetcode. Hence proposing a new solution. Can verify it in leetcode. --- Order and Deliver/# 1251. Average Selling Price.sql | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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 ;