Convert a Purchase at Its Historical Exchange Rate
Problem statement
A purchase has a price in an international currency and a timestamp. Exchange-rate changes are recorded with the timestamp at which each rate becomes effective.
Return the amount payable in internal currency by using the latest exchange rate whose timestamp is less than or equal to the purchase timestamp.
The original assessment fetched the purchase through a local REST endpoint and read the rate history from MySQL. In this practice runner, those two source inputs are supplied directly as tables.
Table schema
Pandas
Use the same input data with any supported language. Open the Schema tab in the editor to see the generated SQL setup or Pandas DataFrames.
purchase
| Column | Type | Nullable | Description |
|---|---|---|---|
| product_name | Text | No | — |
| product_price | Integer | No | — |
| purchase_timestamp | Integer | No | — |
currency
| Column | Type | Nullable | Description |
|---|---|---|---|
| rate_timestampPK | Integer | No | — |
| exchange_rate | Integer | No | — |
Expected result
Your query or function must return these columns.
| Column | Type | Nullable | Description |
|---|---|---|---|
| amount_to_pay | Integer | No | — |
Row order: must match exactly. Numeric tolerance: 0.
Constraints
- The
purchasetable contains exactly one row. - At least one currency row is effective at the purchase timestamp.
- Currency timestamps are unique.