sql实战 查找字符串'10,A,B' 中逗号','出现的次数cnt
问题描述
查找字符串’10,A,B’ 中逗号’,'出现的次数cnt。
来源:牛客网
链接:https://www.nowcoder.com/practice/e3870bd5d6744109a902db43c105bd50?tpId=82&&tqId=29819&rp=1&ru=/ta/sql&qru=/ta/sql/question-ranking
Sql语句
length函数计算出字符串的长度,再使用repalce函数去除,,做差相减即可
select length('10,A,B') - length(replace('10,A,B', ',', '')) as cnt;