|
01.02.2007, 16:41 | #1 |
Участник
|
А еще CTE (они, кстати, появились в MS SQL 2005) можно определять рекурсивно:
Код: WITH DirectReports(ManagerID, EmployeeID, EmployeeLevel) AS ( SELECT ManagerID, EmployeeID, 0 AS EmployeeLevel FROM HumanResources.Employee WHERE ManagerID IS NULL UNION ALL SELECT e.ManagerID, e.EmployeeID, EmployeeLevel + 1 FROM HumanResources.Employee e INNER JOIN DirectReports d ON e.ManagerID = d.EmployeeID ) SELECT ManagerID, EmployeeID, EmployeeLevel FROM DirectReports ; Последний раз редактировалось belugin; 01.02.2007 в 16:43. |
|