开发者

Select Price range - MySQL Query

开发者 https://www.devze.com 2023-01-26 13:32 出处:网络
I need to select a price range from 0 to 50 euros.开发者_StackOverflow中文版 I have this query: SELECT * FROM products WHERE price >= 0 AND price <= 50;

I need to select a price range from 0 to 50 euros.

开发者_StackOverflow中文版

I have this query:

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

Is there a better way to do it?


There is BETWEEN:

SELECT * FROM products WHERE price BETWEEN 0 AND 50;

but its behaviour is different. It selects values that are equal to the starting points as well, so >= instead of > and <= instead of <.


SELECT * FROM products WHERE price BETWEEN 0 AND 50;


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'
0

精彩评论

暂无评论...
验证码 换一张
取 消