mysql - 根据货币订购价格

标签 mysql

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

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/

相关文章:

UTF-8 数据库的 MySQLDump 备份有字符损坏,但默认字符集是正确的

java - Tomcat JDBC 连接池 - 连接卡在 Activity 状态

mysql - 获取所有购买了 2 个产品的客户

mysql - sql问题 Select * From * where one=two order by

mysql - Presto 如何使用 Try_Parse

php - MySQL 查询 - 如何获取相关标签的数量

mysql - Sequelize - 原始 :true and raw:false 和有什么区别

mysql select查询优化

sql - MySQL select from db效率和耗时

mysql:源错误 2?