执行sql语句
WITH COMMENT_CTE(ClassID,ClassParentID,ClassName)
AS
(
SELECT ClassID,ClassParentID,ClassName FROM HardwareClass
WHERE ClassParentID='126'
UNION ALL
SELECT c.ClassID,c.ClassParentID,c.ClassName FROM HardwareClass AS c
INNER JOIN COMMENT_CTE AS ce
ON c.ClassParentID=ce.ClassID)
SELECT * FROM COMMENT_CTE;
结果如下: