99.80% BEAT, easy solution with JOIN and Aggregate Functions
Code\nsql\nSELECT\n    p.product_id AS product_id,\n    ROUND(SUM(u.units * p.price) / SUM(u.units), 2) AS average_price\n\nFROM\n    Prices AS p JOIN\n    Unit
# Code\n```sql\nSELECT\n    p.product_id AS product_id,\n    ROUND(SUM(u.units * p.price) / SUM(u.units), 2) AS average_price\n\nFROM\n    Prices AS p JOIN\n    UnitsSold AS u\n\nON (\n    (u.purchase_date BETWEEN p.start_date AND p.end_date) AND\n    u.product_id = p.product_id\n)\n\nGROUP BY p.product_id\n```
['MySQL']