Ordering price when multi-currency table
I have a table, lets call it products, that includes 2 columns for price and currency. Its dealing with euros, pounds and dollars.
I want to be able to generate the logic that can sort the table on the price, but by taking into account the currency exchange rates.
So, lets say the PRODUCTS table has the following records:
Price Currency
5 £
1 $
7 â¬
If you were to simply sort ascending on Price, it would return:
1
5
7
But if we want to return the results ASCending, according to lowest price value first (taking exchange rate into account), it would need to return:
1
7
5
I do have a RATES table stored in SQL, that has this structure:
id from to rate
-------------------
1 eur gbp 0.683
etc
Which has all of the conversion rates for all possibilities stored in it.
Does anyone have any ideas of the type of SQL code that could achieve this?
|