您的位置:首页 >Mysql以某"字符串"开头的查询方式是什么
发布于2023-04-28 阅读(0)
扫一扫,手机访问
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%";
| id | int |
|---|---|
| name | varchar |
| 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。
不建议不同类型的数据进行比较。
售后无忧
立即购买>office旗舰店
售后无忧
立即购买>office旗舰店
售后无忧
立即购买>office旗舰店
售后无忧
立即购买>office旗舰店
正版软件
正版软件
正版软件
正版软件
正版软件
1
2
3
7
9