loading

获取每行字符串字段逗号个数

(题目)[https://www.nowcoder.com/share/jump/4394623561720098946857]

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');

将所有逗号去掉,原始长度-修正后的长度。

select id,length(string)-length(replace(string,",","")) from strings;

posted @ 2024-07-04 21:24  EaApple  阅读(23)  评论(0)    收藏  举报