mysql 数据库字符串查询6920533939703649410 与6920533939703649419能互查结果

mysql 数据库字符串查询6920533939703649410 与6920533939703649419能互查结果
服务器上的版本不知道,上面是我本地mysql版本
数据表如下

mysql 数据库字符串查询6920533939703649410 与6920533939703649419能互查结果
查询结果1

mysql 数据库字符串查询6920533939703649410 与6920533939703649419能互查结果

查询结果2
mysql 数据库字符串查询6920533939703649410 与6920533939703649419能互查结果

为什么啊

字段类型改成整型,可正常查询

补充

谢谢大家, 字段是字符串类型, 字段值是整型, 加引号后就可以正确筛选了.
之所以出现这种情况,是因为参值太大, 但又被BIGINT的取值范围吓到, 为了方便给设置了string类型, 现在已经改成BIGINT,能正常搜索了

《L05 电商实战》
从零开发一个电商项目,功能包括电商后台、商品 & SKU 管理、购物车、订单管理、支付宝支付、微信支付、订单退款流程、优惠券等
《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
aab
最佳答案

看代码感觉应该是数据类型不对导致的自动转换,可以把查询的数字变成字符串,应该就能解决问题.

select '6920533939703649410' + 0, '6920533939703649419' + 0, cast('6920533939703649410' as double)
1年前 评论
讨论数量: 8
aab

看代码感觉应该是数据类型不对导致的自动转换,可以把查询的数字变成字符串,应该就能解决问题.

select '6920533939703649410' + 0, '6920533939703649419' + 0, cast('6920533939703649410' as double)
1年前 评论

你的 order_no 是 int 类型么? 不是 int 类型你用 int 类型去查什么?

When an operator is used with operands of different types, type conversion occurs to make the operands compatible. Some conversions occur implicitly.
If one or both arguments are NULL, the result of the comparison is NULL, except for the NULL-safe <=> equality comparison operator. For NULL <=> NULL, the result is true. No conversion is needed.
If both arguments in a comparison operation are strings, they are compared as strings.
If both arguments are integers, they are compared as integers.
Hexadecimal values are treated as binary strings if not compared to a number.
If one of the arguments is a TIMESTAMP or DATETIME column and the other argument is a constant, the constant is converted to a timestamp before the comparison is performed. This is done to be more ODBC-friendly. This is not done for the arguments to IN(). To be safe, always use complete datetime, date, or time strings when doing comparisons. For example, to achieve best results when using BETWEEN with date or time values, use CAST() to explicitly convert the values to the desired data type.
1年前 评论
sanders

有没有一种可能是你查询值没有带引号导致的 :smiley:

file

1年前 评论

没加引号导致的类型转换. mysql小窍门: 查询宁可引号, 也不要不加引号

1年前 评论

除此之外,还需要注意,如果字段类型是 varchar、char 等字符串类型时,如果你给定一个数字值去查询时,会导致这一列无法走到索引,反之却不会。

1年前 评论

字符串类型不带' 号,你传入int 类型, 会发生内部隐式转换,给你转成整型,如果长度超过 整型的 比如int 能代表的最大数值,你那个字符串的数字就是一样的结果了

1年前 评论
yangweijie

bigint 遇到 一个设11 一个设16 然后11的存了13 16的存13。 navicat 里查询时 显示不一样但是用cast 转换为字符串后 显示的一样 导致 查用int查的时候 又相等了。用int 也得小心长度 最好设大了

1年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!