Please find the below sample data. There are 2 tables Transaction and Exchange rate. If i need to convert the transactions table to USD,GBP and EUR then below is the query which i have tried but it doesnt give the required output.
Transaction
Currency | Local_Price |
---|---|
USD | 1000 |
GBP | 100 |
EUR | 10 |
USD | 100 |
ExchangeRate
From_Currency | To_Currency | Exchange_Rate |
---|---|---|
USD | GBP | 0.9 |
EUR | USD | 1.1 |
GBP | USD | 1.3 |
EUR | GBP | 0.9 |
Expected Output
Currency | Local_Price | In_USD | In_GBP | In_Eur |
---|---|---|---|---|
USD | 1000 | 1000 | 900 | 80 |
GBP | 100 | 130 | 100 | 99 |
EUR | 10 | 11 | 9 | 10 |
USD | 100 | 100 | 90 | 98 |
Query
Select Currency,Local_price, local_price(coalesce(Exchange_Rate,1)) as In_USD,
from Transaction T
left join ExchangeRate ER on T.Currency=ER.From_Currency
and To_Currency in ('USD','GBP','EUR')
I do not have data from USD to USD or EUR to EUR or GBP to GBP in my exchange rate table.
Please help me with the query for required output.
local_price()
? Can you also show this ? – SquirrelUSD
toEUR
in theExchangeRate
table. Do you have all possible permutation for the required result ? – SquirrelUSD - GBP - 0.9
andEUR - GP - 0.9
. SoUSD - EUR - 1.0
? ? – Squirrel