- Get all child nodes of the specified node ID - the WITH the TEMP the AS ( SELECT * FROM table_name WHERE Id='4' --表的主键ID UNION ALL SELECT T0.* FROM TEMP,table_name T0 WHERE TEMP.Id=T0.ParentId --子级ID==父级ID ) SELECT * FROM TEMP; - Get all the parent node according to the specified node ID - the WITH the TEMP the AS ( SELECT * FROM table_name WHERE Id='32' --表的主键ID UNION ALL SELECT T0.* FROM TEMP,table_name T0 WHERE TEMP.ParentId=T0.Id --父级ID==子级ID ) SELECT * FROM TEMP;
Original Address: https: //www.cnblogs.com/fengyeqingxiang/p/10947815.html