문제

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.

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top