gpt4 book ai didi

php - 在包含多种货币的表中搜索

转载 作者:行者123 更新时间:2023-11-29 11:31:34 25 4
gpt4 key购买 nike

我有这些表

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com