From a02f55b605872e7396276b6e5de0b7895ee2cb5e Mon Sep 17 00:00:00 2001 From: Anamika Singh Raj Date: Sat, 3 Jan 2026 17:36:34 +0530 Subject: [PATCH] Update SQL query for average selling price Refactor SQL query to handle null values in average price calculation. --- README.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 608c120..19a0904 100644 --- a/README.md +++ b/README.md @@ -161,14 +161,17 @@ ORDER BY rating DESC [1251. Average Selling Price](https://leetcode.com/problems/average-selling-price/) ```sql --- avg(selling), round 2 SELECT p.product_id, - ROUND(SUM(price * units) / SUM(units), 2) AS average_price + ROUND( + IFNULL(SUM(price * units) / SUM(units), 0), + 2 + ) AS average_price FROM Prices p LEFT JOIN UnitsSold s ON p.product_id = s.product_id AND purchase_date BETWEEN start_date AND end_date -GROUP BY p.product_id +GROUP BY p.product_id; + ``` [1075. Project Employees I](https://leetcode.com/problems/project-employees-i)