TEKsystemsOA #2
Currency Exchange Rate (SQL)
估计中等评测数据准备中,可先阅读题面
考点(AI 标注)SQL
There are two tables: sales_amount and exchange_rate. When the exchange rate changes, a new row is inserted into exchange_rate with a new effective_start_date for that (source, target) pair.
Write a query that returns the total sales amount in USD for each sales_date, rounded to two decimals (with trailing zeros), ordered by sales_date.
Schema:
sales_amount(sales_date varchar, sales_amount int, currency varchar)
exchange_rate(source_currency varchar, target_currency varchar, exchange_rate numeric(18,2), effective_start_date varchar)
Sample data:
sales_amount:
2020-01-01 500 INR
2020-01-01 100 GBP
2020-01-02 1000 INR
2020-01-02 500 GBP
2020-01-03 500 INR
2020-01-17 200 GBP
exchange_rate:
INR USD 0.14 2019-12-31
INR USD 0.15 2020-01-02
GBP USD 1.32 2019-12-20
GBP USD 1.30 2020-01-01
GBP USD 1.35 2020-01-16
Expected output:
2020-01-01 200.00
2020-01-02 800.00
2020-01-03 75.00
2020-01-17 270.00