递归选择?

递归选择?,第1张

递归选择?

这应该做到这一点

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



欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5508892.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-13
下一篇 2022-12-13

发表评论

登录后才能评论

评论列表(0条)

保存