ROUND | SUM | IFNULL (null error solved)
\n# Code\n\n# Write your MySQL query statement below\nSELECT p.product_id, IFNULL(ROUND(SUM(p.price*u.units)/SUM(u.units), 2),0)\nAS average_price FROM prices p
\n# Code\n```\n# Write your MySQL query statement below\nSELECT p.product_id, IFNULL(ROUND(SUM(p.price*u.units)/SUM(u.units), 2),0)\nAS average_price FROM prices p LEFT JOIN unitssold u \nON p.product_id=u.product_id \nAND u.purchase_date BETWEEN p.start_date AND p.end_date\nGROUP BY p.product_id \n```\n![IMG_20240130_182554.png](https://assets.leetcode.com/users/images/79eab308-8445-40aa-80f0-0ca98cc054a6_1706620714.3325906.png)\n
['MySQL']