I would like to show several columns from the orders table, one of which is derived showing GBP order prices which have been converted using an exchange rate in another table. The exchange rate itself is dependent on two other columns in the orders table.
The 2 tables are:
TABLE `orders`
`id`
`customer`
`season_id`
`order_id`
`style_id`
`quantity`
'currency'
`order_price`
TABLE `forex`
`id`
`currency`
`season_id`
`rate`
currency | season_id | rate
USD | W2012 | 1.5600
USD | S2012 | 1.5100
EUR | W2012 | 1.1510
EUR | S2012 | 1.1800
CAD | S2012 | 1.4600
CAD | S2012 | 1.5010
I need to convert order_price (orders table) to a GBP order price using the appropriate exchange rate (rate in forex table) which depends on the currency type (e.g. USD, EUR – currency in the orders table) and varies with season (e.g. Winter, Spring – season_id in the orders table)
So the echo of the orders table to the browser should look something like:
customer|season_id |style_id|quantity|currency|order_price|rate |price GBP|
USA |W2012 |6200 |2,550 |USD |35,000 |1.5600 |22,436 |
Germany |W2012 |6200 |3,000 |EUR |45,000 |1.1510 |39,096 |
Germany |S2012 |7220 |5,000 |EUR |55,000 |1.1650 |47,210 |
So the statement would be along the lines of: show the exchange rate from the exchange_rate table which corresponds to the season_id and currency in the orders table.
How do I get the correct exchange rate in the select statement to be able to show the GBP order price alongside the other columns?
Apologies for messy explanation, still quite green in this area but boy do I want to learn more!
Thanks,
Derek.
Between, mysql does not have a native support for currency format
12,300,if you require that, it will need some extra processing to format the string / numbe.