A product's price changes over time; prices lists each price with the date range (start_date to end_date, inclusive) when it applied, and the ranges for a product never overlap. units_sold records sales by date. A product's average selling price is the total revenue (units × the price in effect on the purchase date) divided by total units sold. Products with no sales show 0. Write an SQL query that returns product_id and average_price rounded to 2 decimal places. Order the results by product_id ascending.
Loading…
Try solving the question with the schema explorer and hints first. When ready, reveal the verified canonical query and step-by-step logic breakdown.
Ask questions, share alternate queries, and explore solutions
Your recent query executions and answer checks
This will insert the verified MySQL solution into your editor so you can study how each clause transforms the table.