SQLQuokka
Start practicing
QuestionsLearnSandboxFeaturesRoadmapFAQ

Weighted Average Selling Price

Unsolved

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.

SQL Query Editor (Ctrl+Enter to run)
0 characters · Valid
Canonical Solution Official

Official Solution is Hidden

Try solving the question with the schema explorer and hints first. When ready, reveal the verified canonical query and step-by-step logic breakdown.

Community Q&A & Discussion

Ask questions, share alternate queries, and explore solutions

0 comments
Asked By:
Classic pattern · not tied to a specific company

Submission History

Your recent query executions and answer checks

Execution Pipeline:
FROM prices
Full source dataset
5 rows total
Ready. Type a query to see live execution.
Clause: Auto-Sync · AlaSQL Engine