私の問題は「再帰クエリ」で解決できると思いますが、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
入力テーブルを使用して、すべての従業員の階層内のマネージャーを (役割タイプごとに別々の列に) リストする役割テーブル (出力テーブル) を作成したいと考えています。ロールは一意のキーであり、親ロールは入力テーブルの階層を定義します。これであなたの助けに感謝します!