MySQL中like模糊查询

like模糊查询,支持%和下划线匹配,%匹配多个字符,_下划线:任意一个字符
示例:

1、查询名字中含有张的学生信息
select * from student where sname like ‘%张%’;
2、查询名字以张开头的学生信息
select * from student where sname like ‘张%’;
3、查询名字以人结尾的学生信息
select * from student where sname like ‘%人’;
4、查询名字中第二个字为心的学生信息
select * from student where sname like ‘_心%’;
5、查询名字中第三个字为心的学生信息
select * from student where sname like ‘__心%’;

因为下划线在sql中有特殊含义,所以当查询姓名中有下划线的学生信息时需要转义
示例:
select * from student where sname like ‘%_%’;

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐