oracle | simple solution | using sum and round
\n\n# Approach\nwhich join used ?\n\nneed to use join to fetch data from both the table. here we are using left join as it will pull the product_id from prices 
\n\n# Approach\nwhich join used ?\n\nneed to use join to fetch data from both the table. here we are using left join as it will pull the product_id from prices table  even though we dont have units sold.\n\nwhy coalesce ?\nused to convert null value into desired number.\nhere if  the product_id doesnt have any units sold for that , then it will show null as value in average_price. just to convert that null to 0 we have use coalesce.\n\nwhy round ?\n\nused to round the average to 2 decimal point.\n\n\n\n\n\n\n\n# Code\n```\n/* Write your PL/SQL query statement below */\nselect p.product_id ,Coalesce(round(sum(p.price * u.units) / sum(u.units),2),0) as average_price from 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\n```
['Oracle']