with t as ( select tag, count(1) as cnt from exam_record join examination_info on exam_record.exam_id=examination_info.exam_id group by tag ) select t.tag,t1.cnt as answer_cnt from t join t as t1 on upper(t.tag)=t1.tag and t.tag<>t1.tag and t.cnt<3
with t as ( select tag, count(1) as cnt from exam_record join examination_info on exam_record.exam_id=examination_info.exam_id group by tag ) select t.tag,t1.cnt as answer_cnt from t join t as t1 on upper(t.tag)=t1.tag and t.tag<>t1.tag and t.cnt<3