这应该做到这一点:
with recursive all_posts (id, parentid, root_id) as ( select t1.id, t1.parent_forum_post_id as parentid, t1.id as root_id from forumposts t1 where t1.parent_forum_post_id is null union all select c1.id, c1.parent_forum_post_id as parentid, p.root_id from forumposts c1 join all_posts p on p.id = c1.parent_forum_post_id)select root_id, count(*)from all_postsorder by root_id;
您可以通过修改条件来更改“起点”
where t1.parent_forum_post_id is null。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)