[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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

周小董

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值