我有这些表
Currencies Table
Columns : curn_I'd, curn_name, curn_rate
Products Table
Columns : pro_I'd, pro_price, pro_currency -- Pro_currency in Products Table come from curn_id in the Currencies table
这样,例如我有以下情况:
Product table's data as
Id Price Currency
1 100 2
2 200 5
3 300 1
4 400 5
5 500 4
这意味着我有许多不同价格和不同货币类型的产品。
如何搜索价格在 200 到 400 美元之间的产品。
在查询数据库然后搜索所有产品之前,我需要某种方式将所有价格转换为美元。
最佳答案
以下 SQL 查询将通过匹配货币和产品表来连接货币和产品表,并列出产品 ID 以及相应货币的产品价格。
SELECT
p.id, p.pro_price * c.curn_rate, c.curn_id
FROM
products p, currencies c
WHERE
p.pro_currency = c.curn_id;
关于php - 在包含多种货币的表中搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37314233/