postgre sql递归查询

WITH  RECURSIVE  r  AS (
SELECT * FROM [表] WHERE id = xxx
union ALL
SELECT [表].* FROM [表], r WHERE [表].id = r.parent_id
)
SELECT * FROM r ORDER BY id;

 

递归向上查询数据

posted @ 2018-11-16 23:55  Snail90  阅读(662)  评论(0编辑  收藏  举报