mysql查询以某"字符串"开头的查询
查询不以某个或者某些字符串为开头的字符串
1、使用left()函数
select * from order where left(id,2)<>"ab";
2、使用like
select * from order where id not like "%ab%";
查询以某个或者某些字符串为开头的字符串
1、使用left()函数
select * from order where left(id,2)="ab";
2、使用like
select * from order where id like "%ab%";
mysql查询条件字符串类型 = 0
假如有表a
id | int |
---|---|
name | varchar |
a表中有以下数据
id | name |
---|---|
1 | 张三 |
2 | 李四 |
3 | 2王五 |
执行以下sql:
select * from a where name = 0;
会将id=1,id=2的结果返回。
select * from a where name = 2;
会将id=3的结果返回。
为什么?
因为mysql “strings are automatically converted to numbers and numbers to strings as necessary”,字符串自动转换为数字,数字自动转换为字符串 。
当字符串和数字比较时,mysql会从字符串开头截取数字,没有数字的直接转成0。
不建议不同类型的数据进行比较。
以上为个人经验,希望能给大家一个参考,也希望大家多多支持<计算机技术网(www.ctvol.com)!!>。
需要了解更多数据库技术:Mysql查询以某"字符串"开头的查询方式,都可以关注数据库技术分享栏目—计算机技术网(www.ctvol.com)!
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/dtteaching/1209740.html