gpt4 book ai didi

mysql - 如何在mysql中检查带有前导零的varchar

转载 作者:行者123 更新时间:2023-11-30 22:18:09 25 4
gpt4 key购买 nike

以下查询中的条件返回真结果,但我想要假结果。请给我建议。

select *
from test
where
'00160001' between '0013001' and '0023000' OR
'00200000' between '0013001' and '0023000'

最佳答案

没有前导零你会得到相同的结果。
使用整数数据类型来比较整数值。
您还可以使用 cast 即时转换值:

http://dev.mysql.com/doc/refman/5.7/en/cast-functions.html

你的 Cast 示例:

select if( cast('00160001' as unsigned) between cast('0013001' as unsigned)  
and cast('0023000' as unsigned),1,0) as test_a,
if( cast('00200000' as unsigned) between cast('0013001' as unsigned)
and cast('0023000' as unsigned),1,0) as test_b;

关于mysql - 如何在mysql中检查带有前导零的varchar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37528367/

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