Prices change over time and orders must be valued at the price in effect when they were placed. Return each order with the price that was current at ordered_at.
valid_from that is not after ordered_atnullvalid_from take the higher priceorder_idorders| order_id | ordered_at | product_id |
|---|---|---|
| 1 | 2024-02-10 12:00:00 | 55 |
| 2 | 2024-03-05 08:30:00 | 55 |
price_history| price | product_id | valid_from |
|---|---|---|
| 19.99 | 55 | 2024-01-01 00:00:00 |
| 24.5 | 55 | 2024-03-01 00:00:00 |
| order_id | product_id | ordered_at | price |
|---|---|---|---|
| 1 | 55 | 2024-02-10 12:00:00 | 19.99 |
| 2 | 55 | 2024-03-05 08:30:00 | 24.5 |
orders| order_id | ordered_at | product_id |
|---|---|---|
| 1 | 2024-04-01 00:00:00 | 10 |
| 2 | 2024-04-01 00:00:00 | 20 |
price_history| price | product_id | valid_from |
|---|---|---|
| 5 | 10 | 2024-01-01 00:00:00 |
| 8 | 20 | 2024-01-01 00:00:00 |
| order_id | product_id | ordered_at | price |
|---|---|---|---|
| 1 | 10 | 2024-04-01 00:00:00 | 5 |
| 2 | 20 | 2024-04-01 00:00:00 | 8 |
Community-reported interview topic. Not an official company question and no affiliation is implied.
Run against the public tests, or submit to score against all of them.