为什么我不能连接外部连接表?

xe55xuns  于 2021-07-26  发布在  Java
关注(0)|答案(0)|浏览(161)

我有一张老师的table,每个老师也可以当校长。我得介绍一位老师和他的所有校长。他在这段代码中为我做得很好:

WITH teacherTablecte AS
   (SELECT teacher.IdTeacher, teacher.FirstName, teacher.LastName, 
   teacher.PhoneNumber,teacher.ManagerId, 1 as 'EmpLevel', boss.[FirstName]+' 
   '+boss.LastName  as bossName
   FROM [dbo].[T_Teachers]  teacher JOIN  [dbo].[T_Teachers] boss
   ON teacher.ManagerId = boss.IdTeacher
   WHERE teacher.IdTeacher =2011
   UNION ALL
   SELECT teacher.IdTeacher, teacher.FirstName, teacher.LastName, 
   teacher.PhoneNumber,teacher.ManagerId, teacherTablecte.EmpLevel + 1, boss. 
   [FirstName]+' '+boss.LastName 
   FROM  [dbo].[T_Teachers] teacher 
   JOIN teacherTablecte
   ON teacher.IdTeacher = teacherTablecte.ManagerId  JOIN [dbo].[T_Teachers] 
   boss on 
   teacher.MANAGERID= boss.IdTeacher
   )
   SELECT *
   FROM teacherTablecte

但他没有把我介绍给我试图转变的首席执行官

WITH teacherTablecte AS
  (SELECT teacher.IdTeacher, teacher.FirstName, teacher.LastName, 
  teacher.PhoneNumber,teacher.ManagerId, 1 as 'EmpLevel', boss.[FirstName]+' 
  '+boss.LastName  as 
  bossName
  FROM [dbo].[T_Teachers]  teacher JOIN  [dbo].[T_Teachers] boss
  ON teacher.ManagerId = boss.IdTeacher
  WHERE teacher.IdTeacher =2011
  UNION ALL
  SELECT teacher.IdTeacher, teacher.FirstName, teacher.LastName, 
  teacher.PhoneNumber,teacher.ManagerId, teacherTablecte.EmpLevel + 1, boss. 
  [FirstName]+' 
  '+boss.LastName 
  FROM  [dbo].[T_Teachers] teacher 
  JOIN teacherTablecte
  ON teacher.IdTeacher = teacherTablecte.ManagerId  OUTER JOIN [dbo]. 
  [T_Teachers] boss on 
  teacher.MANAGERID= boss.IdTeacher
    )
     SELECT *
     FROM teacherTablecte

但是join到outer join但是我得到这个错误:msg 462,level 16,state 1,line 2 outer join在递归公共表表达式'teachertablecte'的递归部分是不允许的。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题