[886]mysql查询以某个字符开头

时间:2022-07-22
本文章向大家介绍[886]mysql查询以某个字符开头,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

要查询以某个字符开头的数据,在Mysql中常常用到。常用的语句有:

下面以查询文章标题以“正”字开头的语句为例:

  • 使用通配符:
SELECT * FROM `article` where title like '正%';
  • 使用left函数:
SELECT * FROM `article` where left(title,1)='正';
  • 使用字符串截取函数:
SELECT * FROM `article` where substring(title,1,1)='正';
  • 以指定字母开头
select * from a where a.name REGEXP ''^(A|z)'';
select * from a where a.name REGEXP ''^[A|z]'';
  • 不是以数字开头
select * from mot_terms where `name` not REGEXP '^[0-9]' 
  • 以字母开头
select * from mot_terms where `name` REGEXP '^[a-zA-Z]' 
  • 已知数字和特殊字符开头
select * from mot_terms where `name` REGEXP '^[@#$%&0-9]' 

参考:http://www.deardai.com/mysql/idbt94.html https://blog.csdn.net/mimi_csdn/article/details/79446643