Postgres | Oracle solution. Perform GROUP BY and INNER JOIN. Beats 50 % ⬆︎
Approach\n Describe your approach to solving the problem. \n1. We should select all products that were purchased in correct dates. Otherwise we get the incorrec
# Approach\n<!-- Describe your approach to solving the problem. -->\n1. We should select all products that were purchased in correct dates. Otherwise we get the incorrect duplicate records.\n2. After completing this step we just perform `GROUP BY` operation.\n\n# Code\n```\n/* Write your PL/SQL query statement below */\n\nSELECT \n    p.product_id,\n    ROUND(SUM(u.units * p.price)/SUM(u.units), 2) AS average_price\nFROM \n    Prices p \n    INNER JOIN UnitsSold u ON p.product_id = u.product_id\nWHERE\n    u.purchase_date >= p.start_date AND u.purchase_date <= p.end_date\nGROUP BY \n    p.product_id;\n\n```
['Database', 'Oracle']