SQL SERVER
\n# Code\n\nSELECT p.product_id,\n\t\tROUND(SUM(price * ISNULL(units,0))*1.00 / ISNULL(SUM(units),1),2) AS average_price FROM prices p\nLEFT JOIN UnitsSold u ON
\n# Code\n```\nSELECT p.product_id,\n\t\tROUND(SUM(price * ISNULL(units,0))*1.00 / ISNULL(SUM(units),1),2) AS average_price FROM prices p\nLEFT JOIN UnitsSold u ON u.product_id = p.product_id AND purchase_date BETWEEN start_date AND end_date\nGROUP BY p.product_id\n```
['MS SQL Server']