0

我认为我的问题可以通过“递归查询”来解决,但是由于 MySQL 不支持递归查询,所以有人可能会建议我如何处理这个问题?

这是我需要做的一个例子:

输入表员工:

Role | Parent_Role| Person    | Geo| Region |District
----------------------------- -----------------------

Rep-1   DM-1    Lou Gertsner    AME West    CA

Rep-2   DM-1    Steve Ballmer   AME West    CA

DM-1    RVP-1   Marc Benioff    AME West    CA

RVP-1   GEO-1   Ray Ozzie   AME West    Null

WW      Null    Larry Ellison   AME Null    Null

GEO-1   WW  Bill Gates  AME Null    Null

Rep-3   DM-1    Vinod Khosla    AME West    CA

Rep-4   DM-1    Marc Benioff    AME West    CA

输出表

WW_Employee |   Geo_Employee    | Region_Employee | District_Employee|Role  Employee    Geo |   Region |    District |
--------------------------- ----------------------- ------------------------------------

Larry Ellison   Bill Gates  Ray Ozzie   Marc Benioff    Rep-1   Lou Gertsner    AME West    CA

Larry Ellison   Bill Gates  Ray Ozzie   Marc Benioff    Rep-2   Steve Ballmer   AME West    CA

Larry Ellison   Bill Gates  Ray Ozzie   Marc Benioff    DM-1    Marc Benioff    AME West    CA

Larry Ellison   Bill Gates  Ray Ozzie   Null    RVP-1   Ray Ozzie   AME West    Null    

Larry Ellison   Null    Null    Null    WW  Larry Ellison   Null    Null    Null    

Larry Ellison   Bill Gates  Null    Null    GEO-1   Bill Gates  AME Null    Null    

Larry Ellison   Bill Gates  Ray Ozzie   Marc Benioff    Rep-3   Vinod Khosla    AME West    CA  

Larry Ellison   Bill Gates  Ray Ozzie   Marc Benioff    Rep-4   Marc Benioff    AME West    CA  

使用 Input Table ,我想创建一个角色表(输出表),其中列出(按角色类型在单独的列中)每个员工的层次结构中的经理。角色是唯一键,父角色定义输入表中的层次结构。我会感谢你在这方面的帮助!

4

0 回答 0