我认为我的问题可以通过'递归查询'来解决,但由于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
使用输入表,我想创建一个角色表(输出表),列出(按角色类型在不同的列中)每个员工的层次结构中的经理。角色是唯一键,父角色定义输入表中的层次结构。我很感激你的帮助!