描述
现有strings表如下:
- id指序列号;
- string列中存放的是字符串,且字符串中仅包含数字、字母和逗号类型的字符。
请你统计每个字符串中逗号出现的次数cnt。
以上例子的输出结果如下:
示例1
输入:
drop table if exists strings; CREATE TABLE strings( id int(5) NOT NULL PRIMARY KEY, string varchar(45) NOT NULL ); insert into strings values (1, '10,A,B'), (2, 'A,B,C,D'), (3, 'A,11,B,C,D,E');
复制输出:
/* 现有strings表如下:
id指序列号;
string列中存放的是字符串,且字符串中仅包含数字、字母和逗号类型的字符。*/
select s.id, length(s.string)-length(replace(s.string,',',''))
from strings s
1|2 2|3 3|5