Simple Join and an IFNULL function
\n# Code\nmysql []\nSELECT \n    A.product_id, \n    IFNULL(round((SUM(price * units) / SUM(units)), 2), 0) AS average_price\nFROM \n    Prices A\nLEFT JOIN \n 
\n# Code\n```mysql []\nSELECT \n    A.product_id, \n    IFNULL(round((SUM(price * units) / SUM(units)), 2), 0) AS average_price\nFROM \n    Prices A\nLEFT JOIN \n    UnitsSold B\nON \n    A.product_id = B.product_id\nand \n    B.purchase_date BETWEEN A.start_date AND A.end_date\nGROUP BY \n    A.product_id;\n```
['MySQL']