我的知识记录分享
WITH COMMENT_CTE(id,MainID,name,UpdateName,create_id,isdelete, tLevel) AS( SELECT id,MainID,name,UpdateName,create_id,isdelete,0 AS tLevel FROM M_Directory WHERE id =3 UNION ALL SELECT c.id,c.MainID,c.name,ce.UpdateName,c.create_id,c.isdelete,ce.tLevel - 1 FROM M_Directory AS c INNER JOIN COMMENT_CTE AS ce ON c.id = ce.MainID where ce.id <> ce.MainID ) SELECT * FROM COMMENT_CTE where (isdelete=0 or isdelete is null) ORDER BY id ASC
发表评论: