✅ Easy Solution | PostgreSQL ✅
\n\n# Code\n\n-- Write your PostgreSQL query statement below\nSELECT p.product_id,\nCASE\n    WHEN SUM(units) IS NULL THEN 0\n    ELSE ROUND(SUM(units*price)::n
\n\n# Code\n```\n-- Write your PostgreSQL query statement below\nSELECT p.product_id,\nCASE\n    WHEN SUM(units) IS NULL THEN 0\n    ELSE ROUND(SUM(units*price)::numeric/SUM(units),2)\nEND AS average_price\nFROM Prices p LEFT JOIN UnitsSold u\nON p.product_id = u.product_id AND\nu.purchase_date BETWEEN start_date AND end_date\nGROUP BY p.product_id\n```
[]