gpt4 book ai didi

php - mysql varchar字段上的条件之间

转载 作者:行者123 更新时间:2023-11-29 06:19:59 27 4
gpt4 key购买 nike

我在房地产开发网站上工作。特性有两种价格,一种是价格,另一种是价格。

我将其存储为带有连字符的 varchar 字段,如下所示:- 25000-30000。

在搜索记录时,我在条件之间使用了这样的价格 where price between 5000 AND 25000

执行此查询后,它会向我返回具有确切价格的特性。我无法获得中间结果。

最佳答案

Here you will need to differentiate 2 values by - and treat them as mathematical values rather than char. So your query will be like this.

SELECT * from tbl_property WHERE price between 5000 AND 25000 OR ( CAST( SUBSTRING_INDEX(  price,  '-', 1 ) AS UNSIGNED ) between 5000 AND 25000 ) OR ( CAST( SUBSTRING_INDEX(  price,  '-', -1 ) AS UNSIGNED )  between 5000 AND 25000 )

关于php - mysql varchar字段上的条件之间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33795352/

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