0

我需要订购价格,但它有货币,所以它不像看起来那么容易。桌子:

lowmoney | topmoney | currency

1 | 99 | eur
2 | 59 | usd

上面的例子意味着价格是 1.99EUR 和 2.59$ 。有大约 5000 个条目,我需要按实际价格订购,例如 1.99EUR 超过 2.19$,所以

ORDER BY lowmoney DESC, topmoney DESC

不起作用。

PS 只有两种货币 - 美元和欧元。

4

2 回答 2

3
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
于 2013-07-30T20:16:19.517 回答
1

说你有:1 US dollar值得0.7618 Euro

然后

用这个

select concat(`lowmoney`,',', `topmoney`)as money,currency,
       case when `currency` = 'eur' then concat(lowmoney,',' ,topmoney) 
            when `currency` = 'usd' then concat(lowmoney,',' ,topmoney) *  0.7618
            end as money_in_euro  
 from table2
 order by money_in_euro asc

在这里演示

输出:

   MONEY    CURRENCY    MONEY_IN_EURO
   1,99       eur            1,99
   2,59       usd            1.5236
  • 如果您有其他货币,只需添加 WHEN currency = 'gdgd' 然后 concat(...) * the_rate
于 2013-07-30T20:20:32.233 回答