我已在SQL Server上成功运行。我的系统在SQL Server和postgresql上运行。
但是当我从SQL Server更改为postgresql时,它运行失败。
我的sql是这样的:
[(injectedNgModel)]="x"
错误是:
name_tree不存在
如何在postgresql中为孩子获得所有父母
MSQ Server here
中的更多详细信息答案 0 :(得分:1)
尝试:
with RECURSIVE name_tree as
(
SELECT DepartNo, ParentNo FROM Departments
WHERE DepartNo IN (
SELECT DepartNo FROM BelongToDepartment
WHERE UserNo = 1)
union all
select C.DepartNo, C.ParentNo
from Departments c
join name_tree p on C.DepartNo = P.ParentNo
AND C.DepartNo<>C.ParentNo
)
select * from name_tree