Correct solution
Intuition\nCOALESCE()\n\nUse COALESCE, which returns the first not-null value\n\n# Approach\nThis query does not accept test case number 15. It displays incorre
# Intuition\nCOALESCE()\n\nUse COALESCE, which returns the first not-null value\n\n# Approach\nThis query does not accept test case number 15. It displays incorrectly because a left join yields a null value. However, the anticipated result is 0. Therefore, to return 0 value, we utilise COALESCE().\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 MySQL query statement below\nSELECT\n    p.product_id,\n    COALESCE(ROUND(SUM(p.price*u.units) * 1.0 / SUM(u.units), 2),0) AS average_price\nFROM Prices p Left JOIN UnitsSold u\nON (p.product_id = u.product_id) AND (u.purchase_date BETWEEN p.start_date AND p.end_date)\nGROUP BY p.product_id\n```
['MySQL']