查询以检索范围中的正确属性

时间:2015-06-09 05:00:03

标签: php mysql mysqli

我想要检索范围2200000(min_price)到2700000(max_price

的所有属性

查询应该看起来像

SELECT *
FROM properties
WHERE ( ((raw_min >= '{$min_price}')
         OR (raw_min <= '{$max_price}'))
       AND ((raw_max >= '{$min_price}')
            OR (raw_max <= '{$max_price}')))
  AND (..)

查询应满足以下6个条件

raw_min - raw_max
(1) 1000000-2000000 (false)
(2) 1500000- 2400000 (true)
(3) 2300000-2600000  (true)
(4) 2500000-3000000  (true)
(5) 3200000-5000000  (false)
(6) 2000000-3000000  (true)

1 个答案:

答案 0 :(得分:1)

请尝试此查询: -

SELECT * 
FROM properties 
WHERE (raw_min between 2200000 AND 2700000) 
OR (raw_max between between 2200000 AND 2700000) 
OR (raw_min <= 2200000 && raw_max >= 2700000)

请检查我是否更新了查询。