一、查询不以某个或者某些字符串为开头的字段
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