SQL problem - Average Selling Price
Problem
My Query
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 AND (u.purchase_date BETWEEN p.start_date AND p.end_date)
GROUP BY
p.product_id