要查询以某个字符开头的数据,在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