您现在的位置是:网站首页> 编程资料编程资料
Mysql查询以某"字符串"开头的查询方式_Mysql_
2023-05-26
400人已围观
简介 Mysql查询以某"字符串"开头的查询方式_Mysql_
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。
不建议不同类型的数据进行比较。
以上为个人经验,希望能给大家一个参考,也希望大家多多支持。
您可能感兴趣的文章:
相关内容
- MySQL 去除字符串中的括号以及括号里的所有内容_Mysql_
- MySql如何去除字符串前缀,两边,后缀_Mysql_
- mysql中的find_in_set字符串查找函数解析_Mysql_
- mysql中in条件使用字符串方式_Mysql_
- MySQL root账号远程新建数据库报错1044问题及解决方法_Mysql_
- window10系统下mysql5.7安装审计插件(亲测有用)_Mysql_
- MySql执行流程与生命周期详解_Mysql_
- 干涉MySQL优化器使用hash join的方法_Mysql_
- MySQL 中的权限管理及验证流程_Mysql_
- phpstudy中mysql无法启动(与本地安装的mysql冲突)的解决方式_Mysql_
