在某些特定的项目需求中,我们需要实现树状数据结构, 由此,我们需要用递归将数据查询出来。
WITH T AS ( SELECT ID,PID FROM TableName WHERE ID=1 UNION ALL SELECT A.* FROM (SELECT ID,PID FROM TableName) A INNER JOIN T ON A.PID=T.ID ) SELECT * FROM T