Straightforward MS SQL Server solution
Code\n\nselect unitssold.product_id, round(cast(sum(units*price) as float) / sum(units), 2) as average_price from unitssold\nleft join prices on unitssold.produ
# Code\n```\nselect unitssold.product_id, round(cast(sum(units*price) as float) / sum(units), 2) as average_price from unitssold\nleft join prices on unitssold.product_id = prices.product_id and purchase_date >= start_date and purchase_date <= end_date\ngroup by unitssold.product_id\n```
['MS SQL Server']