【发布时间】:2011-12-16 12:56:51
【问题描述】:
我想显示订单表中的几列,其中一个是派生出来的,显示英镑订单价格,该价格已使用另一个表中的汇率转换。汇率本身取决于订单表中的另外两列。
这两个表是:
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
我需要使用适当的汇率(外汇表中的汇率)将 order_price(订单表)转换为英镑订单价格,该汇率取决于货币类型(例如美元、欧元 - 订单表中的货币)并随季节而变化(例如,冬季、春季 - 订单表中的 season_id)
因此,订单表在浏览器中的回显应该类似于:
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 |
因此该语句将类似于:显示 exchange_rate 表中的汇率,该汇率对应于 orders 表中的 season_id 和货币。
如何在选择语句中获得正确的汇率,以便能够在其他列旁边显示英镑订单价格?
对于混乱的解释道歉,在这个领域仍然很绿色,但男孩我想了解更多!
谢谢, 德里克。
【问题讨论】:
标签: mysql