递归地爬上树
WITH RECURSIVE ManagersOfJonathon AS (
-- start with this row
SELECT *
FROM Employees
WHERE ID = 4
UNION ALL
-- get manager(s) of all previously selected rows
SELECT Employees.*
FROM Employees
JOIN ManagersOfJonathon
ON Employees.ID = ManagersOfJonathon.ManagerID
)
SELECT * FROM ManagersOfJonathon;
ID |
FName 参数 | LName | 电话号码 | 经理 ID | DepartmentID |
---|---|---|---|---|---|
4 |
乔纳森 | 工匠 | 1212121212 | 2 | 1 |
2 | 约翰 | 约翰逊 | 2468101214 | 1 | 1 |
1 | 詹姆士 | 工匠 | 1234567890 | 空值 | 1 |