Faster than 99.49% --> LEFT JOIN, Subquery, and SUM + ROUND
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\n/* Write your T-SQL query statement below */\nSELECT t.product_id, ROUND(SUM(t.total_price)*1.0 / SUM(t.units), 2) AS average_price\nFROM(SELECT u.product_id, u.units, p.price, u.units * p.price AS total_price\n    FROM UnitsSold u LEFT JOIN Prices p ON u.product_id = p.product_id\n    WHERE u.purchase_date >= p.start_date AND u.purchase_date <= p.end_date) t\nGROUP BY t.product_id\n\n```
['MS SQL Server']