Read Product Prices at the Fixed Snapshot Date

Quick Overview

Return product_id and price for every product represented in Products as of 2019-08-16. Each product starts at price 10. A change on the snapshot date applies; later changes do not. Row order is unrestricted.

Read Product Prices at the Fixed Snapshot Date

Company: Amazon

Role: Software Engineer

Category: Data Manipulation (SQL/Python)

Difficulty: medium

Interview Round: Other

### Problem Return product_id and price as of 2019-08-16 for every distinct product_id appearing anywhere in Products. Each product starts at price 10. A change on the snapshot date applies; later changes do not. Row order is unrestricted. ### Tables Table: `Products` ```text +---------------+---------+ | Column Name | Type | +---------------+---------+ | product_id | int | | new_price | int | | change_date | date | +---------------+---------+ (product_id, change_date) is the primary key (combination of columns with unique values) of this table. Each row of this table indicates that the price of some product was changed to a new price at some date. ``` ### Example ```text Products (product_id,new_price,change_date): (1,20,2019-08-15), (1,25,2019-08-16), (1,30,2019-08-17), (2,40,2019-08-18) Output (product_id,price): (1,25), (2,10) ``` ### What a Strong Answer Covers - Return a price for each recorded product. - Apply changes through the snapshot date and use the starting price when no change qualifies. ### Follow-up Questions - How would you report prices on several snapshot dates? - How would you handle multiple changes with the same date if the key allowed them?

Overview: Return product_id and price for every product represented in Products as of 2019-08-16. Each product starts at price 10. A change on the snapshot date applies; later changes do not. Row order is unrestricted.

Amazon logo
Amazon
mediumSoftware EngineerOtherData Manipulation (SQL/Python)
0
0

Problem

Return product_id and price as of 2019-08-16 for every distinct product_id appearing anywhere in Products. Each product starts at price 10. A change on the snapshot date applies; later changes do not. Row order is unrestricted.

Tables

Table: Products

+---------------+---------+
| Column Name   | Type    |
+---------------+---------+
| product_id    | int     |
| new_price     | int     |
| change_date   | date    |
+---------------+---------+
(product_id, change_date) is the primary key (combination of columns with unique values) of this table.
Each row of this table indicates that the price of some product was changed to a new price at some date.

Example

Products (product_id,new_price,change_date): (1,20,2019-08-15), (1,25,2019-08-16), (1,30,2019-08-17), (2,40,2019-08-18)
Output (product_id,price): (1,25), (2,10)

What a Strong Answer Covers Guidance

  • Return a price for each recorded product.
  • Apply changes through the snapshot date and use the starting price when no change qualifies.

Follow-up Questions Guidance

  • How would you report prices on several snapshot dates?
  • How would you handle multiple changes with the same date if the key allowed them?