选择多种货币的价格范围

时间:2016-09-26 05:37:39

标签: php mysql

我有一个包含currency_codeprice的mysql表。

currency_code | price

usd | 50

twd | 1570

JPY | 5049

用户可以输入一系列price来搜索产品:

SELECT * FROM product WHERE price between 0 and 1500

如果表格中的currency_code不同,我该如何进行price范围查询?

3 个答案:

答案 0 :(得分:0)

您必须控制所选币种并将其放入查询中:

SELECT * FROM product WHERE price between 0 and 1500
AND currency_code = $selected_currency_code

答案 1 :(得分:0)

从您的问题中我了解到我们有两个如下表格 为便于理解请查看这些示例

id  |currency_id    |price
----------------------------
1   |1              |1000
2   |2              |1500
3   |1              |1300

货币

currency_id |   currency_name
--------------------------------
1           |   Dollor
2           |   Euro

这是一个示例连接查询,可以输出0到1500之间的值

 SELECT price.id,price.price,currency_code.currency_name FROM price 
INNER JOIN currency_code ON price.currency_id = currency_code.currency_id 
WHERE price  BETWEEN 0 AND 1500

答案 2 :(得分:0)

select driver.*,
case
when driver.rental_currency = 'HKD' then driver_rental.HKT_1_fee_full_day / 7.78
when driver.rental_currency = 'TWD' then driver_rental.HKT_1_fee_full_day / 31.4
when driver.rental_currency = 'CNY' then driver_rental.HKT_1_fee_full_day / 6.67
end
as HKT_1_fee_full_day
from driver_rental
left join driver
on
driver.email = driver_rental.email
where
driver_rental.HKT_1_fee_full_day between 0 and 52
;

使用case之后where语句不起作用?