SQL Server
\nSelect product_id, Round(Sum(total_Sales) / Sum(units),2) as average_price from \n(Select u.product_id, p.price, u.units, Cast((price * units) as Float) total
```\nSelect product_id, Round(Sum(total_Sales) / Sum(units),2) as average_price from \n(Select u.product_id, p.price, u.units, Cast((price * units) as Float) total_Sales from Prices p inner join UnitsSold u on \n(p.product_id = u.product_id and u.purchase_date >= p.start_date and u.purchase_date <= p.end_date)) sub \ngroup by product_id\n```
[]