ms sql server solution
select subsub.product_id,\n       round(subsub.total_revenue/subsub.total_units,2) AS average_price\nfrom       \n(select sub.product_id,\n       CAST(SUM(sub.p
select subsub.product_id,\n       round(subsub.total_revenue/subsub.total_units,2) AS average_price\nfrom       \n(select sub.product_id,\n       CAST(SUM(sub.price * sub.units) AS FLOAT)  AS total_revenue,\n       CAST(SUM(sub.units) AS FLOAT) AS total_units\nfrom \n(select u.product_id,\n         p.price,\n         u.units\n  from UnitsSold u, Prices p\n  where (u.purchase_date >= p.start_date) AND (u.purchase_date <= p.end_date) AND (u.product_id = p.product_id) )  sub  \n  group by sub.product_id) subsub
[]