[SQL]1251
1251. 平均售价
日期处于中间使用BETWEEN...AND...
SELECT A.product_id, ROUND(SUM(A.price*A.units)/SUM(A.units),2) AS average_price
FROM (SELECT p.product_id, price, units
FROM Prices p LEFT JOIN UnitsSold u
ON p.product_id = u.product_id
AND purchase_date BETWEEN start_date AND end_date) A
GROUP BY A.product_id;