题目链接:点击打开链接
题目大意:略。
解题思路:略。
AC 代码
--解决方案(1) SELECTt1.sub_idpost_id, COUNT(t2.parent_id) number_of_commentsFROM (SELECT*FROMSubmissionsWHEREparent_idISNULLGROUPBYsub_id) t1LEFTJOIN(SELECT*FROMSubmissionsWHEREparent_idISNOTNULLGROUPBYsub_id, parent_id) t2ONt1.sub_id=t2.parent_idGROUPBYpost_idORDERBYpost_id--解决方案(2) SELECTpost_id, COUNT(sub_id) ASnumber_of_commentsFROM ( SELECTDISTINCTpost.sub_idASpost_id, sub.sub_idASsub_idFROMSubmissionspostLEFTJOINSubmissionssubONpost.sub_id=sub.parent_idWHEREpost.parent_idisnull) TGROUPBYpost_idORDERBYpost_idASC