select substring_index (subject_set, ',', 1) subject_id1, -- 取出第一个数字 count(1) as cnt -- count(1)==count(*),后有group by,因此在这里count的subject_id1的次数 from comment_detail where subject_set regexp '[0-9]*,1002'-- 正则 group by subject_id1
题目解读:subject_set中,每一个数字为一个话题,筛选取出第二个数字为1002的行,并将第一个数字取出来作为subject_id1列,统计subject_id1,并根据subject_id1排序
题目
输入
输出