-1

我想编写一个 SQL ServerSELECT查询,以表格格式以分层方式显示数据。

例如:员工向 X 经理报告,然后 X 经理向 XX 经理报告,然后 XX 经理向 XXX 经理报告 - 对于每一行记录。

表数据:

输入数据格式

输出格式:

输出所需格式

4

1 回答 1

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
....
于 2017-05-22T12:18:03.920 回答