MySQL: LeetCode 1251. Average Selling Price (15/17 Test Cases Passed)
SELECT p.product_id, ROUND(COALESCE(SUM(price * units) / NULLIF(SUM(units), 0), 0), 2) AS average_price FROM Prices p JOIN UnitsSold u ON u.product_id = p.product_id AND u.purchase_date BETWEEN p.start_date AND p.end_date GROUP BY p.product_id; Only passes 15/17 test cases, not sure why Tried…