我想编写一个 SQL ServerSELECT
查询,以表格格式以分层方式显示数据。
例如:员工向 X 经理报告,然后 X 经理向 XX 经理报告,然后 XX 经理向 XXX 经理报告 - 对于每一行记录。
表数据:
输出格式:
我想编写一个 SQL ServerSELECT
查询,以表格格式以分层方式显示数据。
例如:员工向 X 经理报告,然后 X 经理向 XX 经理报告,然后 XX 经理向 XXX 经理报告 - 对于每一行记录。
表数据:
输出格式:
很简单,将 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
....