一、查询不以某个或者某些字符串为开头的字段
1、使用left()函数
select * from order where left(id,2)<>"BJ";
select * from order where left(id,2)<>"BJ" and left(id,2)<>"SH";
2、使用like
select * from order where id not like "%BJ%";
3、使用substring()函数
substring(id,1,2)="BJ" 如果为true返回1,false 返回0
select id,substring(id,1,2)="BJ" as result from t_order having result !=1
二、查询以某个字符串开头
1、使用left()函数
select * from order where left(id,2)="BJ";
2、使用like
select * from order where id like"%BJ%";
3、使用substring()函数
select id,substring(id,1,2)="BJ" as result from t_order having result =1
本文详细介绍了如何使用SQL查询技巧,包括left(), like和substring()函数,来查找以特定字符串开头或不以特定字符串开头的数据记录。这些技巧对于数据库管理和数据检索至关重要。
1046

被折叠的 条评论
为什么被折叠?



