How would one get an Exchange Rate between two currencies in SQL

1.6k views Asked by At

I am trying to write an SQL query that would get the exchange rate for say Sterling to Euro.

I have tried the SQL below:

SELECT CurrencyCode,ExchangeRate FROM Currency
WHERE CurrencyCode='GBP';

I was expecting to get a list of two columns, currency name and exchange rates for sterling, but something is not right; any ideas?

So...

SELECT ExchangeRate FROM Currency WHERE CurrencyCode = 'EUR';  

This would return a single column for all of the rates for EUR against other currencies.

1

There are 1 answers

4
Danny Beckett On BEST ANSWER

Presuming you don't have an intermediate ExchangeRates table, so you're using a base currency instead, if the base currency is GBP, the query you want is:

SELECT ExchangeRate FROM Currency WHERE CurrencyCode = 'EUR';

Here's a demo.