我想编写一个SQL Server SELECT
查询,以表格格式显示分层数据。
喜欢:员工向X经理报告,然后X经理向XX经理报告,然后XX经理向XXX经理报告 - 每行记录。
表格数据:
输出格式:
答案 0 :(得分:1)
简单,一起加入10个虚拟表
Select person, Person1, Person2, ...
from people
left join
(
select person as Person1, Manager as Manager2 from People
) as People1
on people.Manager = Person1
left join
(
select person as Person2, Manager as Manager3 from People
) as People2
on Manager2 = Person2
....