我需要订购价格,但它有货币,所以它并不像看起来那么容易。表格:
lowmoney | topmoney | currency
1 | 99 | eur
2 | 59 | usd
以上示例表示价格为 1.99EUR 和 2.59$。有 ~5000 个条目,我需要按实际价格订购,例如 1.99EUR 超过 2.19$,所以
ORDER BY lowmoney DESC, topmoney DESC
不起作用。
附言只有两种货币 - 美元和欧元。
最佳答案
select
lowmoney,
topmoney,
currency
from TheTable
order by
/* Order by amount in dollars (could calculate to euro as well) */
(lowmoney + (topmoney / 100)) *
case currency
when 'eur' then 1.3266 /* Current exchange rate, according to Google */
when 'usd' then 1
else
null /* What to do with other currencies. */
end desc
关于mysql - 根据货币订购价格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17956354/