MS SQL solution easy
select u.product_id, round(sum(price units 1.0)/sum(units), 2) as average_price\nFROM UnitsSold u JOIN Prices p\nON u.product_id = p.product_id\nand u.purchase_
select u.product_id, round(sum(price* units *1.0)/sum(units), 2) as average_price\nFROM UnitsSold u JOIN Prices p\nON u.product_id = p.product_id\nand u.purchase_date between p.start_date and p.end_date\nGROUP BY u.product_id
[]