Product Price at Date

4pts
Amazon

Problem Statement

Amazon inventory systems track every price change for every product. Management needs a report showing the price of every product exactly on 2019-08-16.

The price of a product at a given date is the price set by the most recent change on or before that date. If a product has no price changes recorded on or before 2019-08-16, its price is assumed to be 10.

Write a query to find the prices of all products on 2019-08-16.

Rules:

  • Include every product that exists in the system.
  • If no price change exists on or before 2019-08-16, the price defaults to 10.
  • Output columns: product_id, price.
  • Results must be sorted by product_id in ascending order.
Tests your understanding of
Window Functions, Subqueries, Grouping and Temporal Data

Input Tables

Products
product_id(INTEGER)product_name(VARCHAR)
1Echo Dot
2Kindle Paperwhite
3Fire Stick
4Ring Doorbell
5Cloud Cam
6Smart Plug
Price_Logs
product_id(INTEGER)new_price(DECIMAL)change_date(DATE)
1202019-08-14
2502019-08-14
1302019-08-15
1352019-08-16
2652019-08-17
3202019-08-18
Warehouse_Inventory
product_id(INTEGER)stock_count(INTEGER)
1100
250
3200
40
510
65

Expected Output

product_id(INTEGER)price(DECIMAL)
135
250
310
410
510
610

Tags

MediumWindow FunctionsSubqueriesGroupingTemporal Data
15-20 min
65%

Hints