当前位置:网站首页>MySQL查询字符串中有多少个相同字符(查询字符串包含特定个数的相同字符)
MySQL查询字符串中有多少个相同字符(查询字符串包含特定个数的相同字符)
2022-07-20 16:58:00 【ㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤ-】
一、准备工作
CREATE TABLE test_a ( id INT(20) PRIMARY KEY AUTO_INCREMENT , fre_a VARCHAR(20) NOT NULL) ;
INSERT INTO test_a VALUES (DEFAULT , ‘b’) ;
INSERT INTO test_a VALUES (DEFAULT , ‘a’) ;
INSERT INTO test_a VALUES (DEFAULT , ‘ab’) ;
INSERT INTO test_a VALUES (DEFAULT , ‘aa’) ;
INSERT INTO test_a VALUES (DEFAULT , ‘aba’) ;
INSERT INTO test_a VALUES (DEFAULT , ‘aaa’) ;
INSERT INTO test_a VALUES (DEFAULT , ‘ababa’) ;
INSERT INTO test_a VALUES (DEFAULT , ‘aaba’) ;
INSERT INTO test_a VALUES (DEFAULT , ‘aaab’) ;
INSERT INTO test_a VALUES (DEFAULT , ‘aaaa’) ;
INSERT INTO test_a VALUES (DEFAULT , ‘aabaa’) ;
INSERT INTO test_a VALUES (DEFAULT , ‘aaaba’) ;
INSERT INTO test_a VALUES (DEFAULT , ‘aaaaa’) ;
INSERT INTO test_a VALUES (DEFAULT , ‘abaaaa’) ;
INSERT INTO test_a VALUES (DEFAULT , ‘aabaaa’) ;
INSERT INTO test_a VALUES (DEFAULT , ‘aabaaba’) ;
二、查询需求
查询出字符串中只有特定个数字符‘a’的字符串,例如查询字符串中有3个‘a’的字符串,需要查出
‘aaa’ , ‘ababa’ ,‘aaba’ ,‘aaab’ 这4个字符串里包含3个’a’字符
三、查询方式
查询字符串里只有3个’a’的字符
1、模糊查询方式
select * from test_a where fre_a not like ‘%a%a%a%a%’ and fre_a like ‘%a%a%a%’ ;
2、正则查询方式
select * from test_a where fre_a not rlike ‘(.a{1}.){4}’ and fre_a rlike ‘(.a{1}.){3}’ ;
3、函数方式
select * from test_a where (select length(fre_a) - length(replace(fre_a , ‘a’ , ‘’))) = 3;
边栏推荐
- 一女子找工作不接受单休遭HR羞辱:我们不是在找小三
- 为什么 this.$refs[formName].validate((valid) =>{} 无效(没有反应)
- Leetcode breaks the 7W mark
- What is skia?
- Intelligent science innovation lecture hall | Institute of automation he Huiguang: Research on deep learning brain mechanism based on visual information encoding and decoding
- Help the AI industry landing, yunzhisheng shows the full stack of AI hard core technology
- Distributed high concurrency and high availability fastdfs file server cluster deployment
- 水泽-信息收集自动化工具安装
- Leetcode中使用BFS解决二叉树相关题目的行动指南
- HTB-Bashed
猜你喜欢
随机推荐
XCTF-ms0_01
水泽-信息收集自动化工具安装
sqlilabs less-27
线性回归模型笔记(2)
How to choose securities companies that support flush? Is it safe to open an account on your mobile phone
个人学习 _numpy
lotus-bench 1.17.0-rc3 Benchmarks
如何使用 Apache Web 服务器配置多个站点
【MySQL】 insert into ... select ...
Why this$ refs[formName]. Validate ((valid) = > {} invalid (no response)
Low code that democratizes software development
联想曝新型UEFI漏洞,影响70款数百万台笔记本电脑
Leetcode中使用BFS解决二叉树相关题目的行动指南
sqlilabs less-26~26a
为什么说Kubernetes是新的应用服务器
为什么要引入线程?
期货开户云上面可以开户吗?在上面开户安全吗?
Uniapp applet adds custom check box style
一女子找工作不接受单休遭HR羞辱:我们不是在找小三
华为P30 Pro拆解:结构紧凑做工精细,核心器件供应商曝光!