题解 | 用substring_index()函数解决
话题的分布情况
https://www.nowcoder.com/practice/3f0d5c83b48b450888921b6189be288f
substring_index():
按照指定分隔符截取字段的前n段(后n段)
函数语法:
substring_index(str,delim,count):
str:要处理的字符串
delim:分隔符
count:截取段数
代码如下:
select substring_index(subject_set,',',1) as subject_id1, count(id) as cnt from comment_detail where substring_index(substring_index(subject_set,',',2),',',-1)='1002' group by subject_id1;
