EASY SQL SOLUTION
\n# Approach\n1)USE JOIN TO MAKE p.product_id = u.product_id\n2)ALSO CHECK IF purchase_date is between start_date and end_date or not\n3)We use INNER JOIN to co
\n# Approach\n1)USE JOIN TO MAKE p.product_id = u.product_id\n2)ALSO CHECK IF purchase_date is between start_date and end_date or not\n3)We use INNER JOIN to combine the "Prices" and "UnitsSold" tables based on the common product_id column.\nWe provide aliases for the tables to make the query more readable (p for "Prices" and u for "UnitsSold").\nThe WHERE clause filters the results to only include rows where the purchase_date from "UnitsSold" falls within the date range defined by the start_date and end_date columns in the "Prices" table.\nThe GROUP BY clause groups the results by product_id.\n4)We use the ROUND function to calculate the average price rounded to two decimal places.\n\n# Code\n```\nSELECT p.product_id, ROUND(SUM(price * units) / SUM(units), 2) AS average_price\nFROM Prices AS p\nINNER JOIN UnitsSold AS u ON p.product_id = u.product_id\nWHERE u.purchase_date BETWEEN p.start_date AND p.end_date\nGROUP BY p.product_id;\n\n```
['Database', 'MySQL']