网络编程
位置:首页>> 网络编程>> 数据库>> Mysql查询以某"字符串"开头的查询方式

Mysql查询以某"字符串"开头的查询方式

作者:第六序列  发布时间:2024-01-24 21:05:19 

标签: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

idint
namevarchar

A表中有以下数据

idname
1张三
2李四
32王五

执行以下sql:

select * from A where name = 0;

会将id=1,id=2的结果返回。

select * from A where name = 2;

会将id=3的结果返回。

为什么?

因为Mysql &ldquo;Strings are automatically converted to numbers and numbers to strings as necessary&rdquo;,字符串自动转换为数字,数字自动转换为字符串 。

当字符串和数字比较时,mysql会从字符串开头截取数字,没有数字的直接转成0。

不建议不同类型的数据进行比较。

来源:https://blog.csdn.net/weixin_55527323/article/details/124038806

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com