遞迴地爬上樹
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 |