MySQL solution - simple and easy
\nSELECT\n    p.product_id,\n    ROUND((SUM(p.price * us.units) / SUM(us.units)), 2) average_price\nFROM prices p \nJOIN UnitsSold us \nON p.product_id = us.pro
```\nSELECT\n    p.product_id,\n    ROUND((SUM(p.price * us.units) / SUM(us.units)), 2) average_price\nFROM prices p \nJOIN UnitsSold us \nON p.product_id = us.product_id\n    AND us.purchase_date BETWEEN p.start_date AND p.end_date\nGROUP BY p.product_id\n```
[]