with a as ( select id,name,parentid from categories where id=53 union all select x.id,x.name,x.parentid from categories x,a where x.parentid=a.id ) select * from a
SQL在一张表中根据父ID获取所有的子ID
原文:https://www.cnblogs.com/chenxizhaolu/p/9273648.html