In the data warehouse, we are receiving transactions from multiple source systems on a regular basis. Below are the sample datasets from one of the transaction system,
AccountId
CountryCode
RelationshipOfficer
CurrencyCode
ProductCode
TransactionDate
Amount
ApprovedBy
MonthendDate
111
SG
5016
SGD
LON
10/11/2016
10,000.00
7015
31/3/2017
111
HK
6011
HKD
OVD
20/3/2017
5,000.00
8214
31/3/2017
111
SG
5016
SGD
LON
10/11/2016
2,000.00
7015
31/3/2017
111
SG
5016
SGD
LON
20/10/2016
8,000.00
7015
30/3/2017
111
SG
5016
SGD
LON
8/7/2016
9,000.00
7015
31/3/2017
111
HK
6011
HKD
OVD
12/10/2016
6,000.00
8214
31/3/2017
222
UK
3014
GBP
OVD
2/1/2017
7,000.00
6011
31/3/2017
222
UK
3014
GBP
OVD
31/12/2016
6,500.00
6011
31/3/2017
222
UK
3014
GBP
OVD
7/11/2016
6,000.00
6011
31/3/2017
222
UK
3014
GBP
LON
31/12/2016
4,000.00
6011
31/3/2017
SourceCurrency
TargetCurrency
ExchangeRate
SGD
USD
0.73
HKD
USD
0.13
GBP
USD
1.32
SGD
EUR
0.64
HKD
EUR
0.11
You are given the task to write code to generate below output.
AccountId
CountryCode
ProductCode
CurrencyCode
Amount
MonthendDate
111
SG
LON
USD
8,760.00
31/3/2017
111
HK
OVD
USD
650.00
31/3/2017
222
UK
OVD
USD
9,240.00
31/3/2017
222
UK
LON
USD
5,280.00
31/3/2017
Hints:
Pick the latest transactions for the combination of AccountId, CountryCode and ProductCode.
If there are multiple transactions for same date and combination, we should add them up.
Convert the amount to USD using the currency rate table provided.
... View more