雪花层次

时间:2020-01-22 17:18:52

标签: sql snowflake-cloud-data-platform

我能够提取经理下的所有员工以及向这些员工汇报的子员工 但我也想获得根管理员的经理行。我该如何实现

    select employee_id, first_name, last_name, manager_id, manager_name
from employee
start  with manager_name = 108
connect by prior employee_id = manager_id

Result

但是我也希望得到经理的经理,如下所示

enter image description here

1 个答案:

答案 0 :(得分:0)

如果应用以下语法会发生什么:

CONNECT BY <col_1_identifier> = PRIOR <col_2_identifier>

通过:

select employee_id, first_name, last_name, manager_id, manager_name
from employee
start  with manager_name = 108
connect by prior employee_id = Prior manager_id