Problem: 1251. 平均售价
🍻 AC code
SELECT p.product_id, ROUND(ifnull(SUM(units * price) / SUM(units), 0),2) AS average_price
FROM prices as p
LEFT JOIN unitsSold as u ON p.product_id = u.product_id
WHERE u.purchase_date BETWEEN p.start_date AND p.end_date or u.product_id is null
GROUP BY p.product_id