gpt4 book ai didi

php - Mysql 将一列拆分为两个值(数字)并在它们之间进行搜索

转载 作者:可可西里 更新时间:2023-11-01 08:31:34 24 4
gpt4 key购买 nike

嗨,我在 mysql 中遇到了这个问题,我的表如下所示

  id        years  1       1985-1996  2       1990-2000

now I will receive a submitted value(yeaer between two,ex 1990) I have to split years into two parts like 1985 as initVal and 1996 endVal

I tried a few things which did not work for me

SELECT * FROM cip_finder WHERE model =33 AND('1986' BETWEEN if(locate('_',years)=0,'',SUBSTRING_INDEX(years, '_', 1)) AND if(locate('_',years)=0,'',SUBSTRING_INDEX(years, '_', 1)))


SELECT *,SPLIT_STR(years, '-', 1) AS initVAL,SPLIT_STR(years, '-', 2) AS endVal FROM cpc_finder WHERE model =33 AND('1986' BETWEEN initVal AND endVal)

有什么解决办法吗

最佳答案

同意 Alma Do 的评论...您需要将年份列标准化为两个。

尽管如果您仍然无法做到这一点,请使用下面的查询,您将获得预期的输出:

SELECT id, SUBSTRING_INDEX( years , '-', 1) AS initVal, 
REPLACE(years,CONCAT(SUBSTRING_INDEX( years , '-', 1),'-'),'') AS endVal
FROM cip_finder;

希望对您有所帮助!

关于php - Mysql 将一列拆分为两个值(数字)并在它们之间进行搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24908017/

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