题解 | #查找字符串中逗号出现的次数#
知识点
- 使用length函数统计字符串的长度,再使用replace把,全部替换掉统计长度,相减就是逗号出现的次数
代码
select id,length(string) - length(replace(string,",","")) as cnt
from strings
补充
- 这题我刚看的时候是'10,A,B,C'只有一个,无限报错不知道为什么。一看结果发现好像有一个表。再刷新一下题目就变了有点无语
select id,length(string) - length(replace(string,",","")) as cnt
from strings
相关推荐