Mysql以某"字符串"开头的查询方式是什么
作者:小确幸
时间:2023-04-28
浏览:2
Mysql查询以某"字符串"开头的查询查询不以某个或者某些字符串为开头的字符串1、使用left()函数select*fromorderwhereleft(id,2)"AB";2、使用likeselect*fromorderwhereidnotlike"%AB%";查询以某个或者某些字符串为开头的字符串1、使用left()函数select*fromorderwhereleft(id,2)="AB";2、使用likeselect*fromorderwhereidlike"%AB%";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。
不建议不同类型的数据进行比较。
作者最新文章
beyond compare怎么自动换行
2026-10-23 10:35
Luminar Neo画笔与蒙版使用指南:精准选区与图层合成技巧
2026-10-22 15:23
Photoshop快捷键表格在哪找
2026-10-22 14:42
漫蛙漫画下载免费安卓最新版本
2026-10-13 13:18
漫蛙下载最新版安装包
2026-10-13 13:18
热门文章
更多
精品专题
更多
Mac软件
更多
WINDOWS
更多

































