mysql选择价格范围

时间:2010-11-22 13:26:06

标签: php mysql

我需要选择0到50欧元的价格范围。

我有这个问题:

SELECT * FROM products WHERE price > 0 AND price < 50;

有更好的方法吗?

3 个答案:

答案 0 :(得分:6)

BETWEEN

SELECT * FROM products WHERE price BETWEEN 0 AND 50;

但它的行为是不同的。它也会选择等于起点的值,因此>=代替><=而不是<

答案 1 :(得分:0)

SELECT * FROM products WHERE price BETWEEN 0 AND 50;

答案 2 :(得分:0)

price value pass
$pricerange = explode('-', str_replace('$','',$searchValue['price_range']));  

 select * from tableName where  model='".$searchValue['model']."' and (price BETWEEN $pricerange[0] and $pricerange[1]) and status='active'