Summing different columns from different Tables with Group BY
\n# Code\n\n/* Write your T-SQL query statement below */\n\nselect p.product_id, \n    ROUND(ISNULL((SUM(p.price * u.units) + 0.00)/ (SUM(u.units) + 0.00), 0), 
\n# Code\n```\n/* Write your T-SQL query statement below */\n\nselect p.product_id, \n    ROUND(ISNULL((SUM(p.price * u.units) + 0.00)/ (SUM(u.units) + 0.00), 0), 2) as average_price\nfrom prices p\nLEFT OUTER join UnitsSold u on p.product_id = u.product_id and \n    p.start_date <= u.purchase_date and \n    p.end_date >= purchase_date\ngroup by p.product_id \n```
['MS SQL Server']