まず、いくつかのデータベース カット:
+-----+----------------------------------------+----------+--------+
| id | name | code | parent |
+-----+----------------------------------------+----------+--------+
| 1 | Basic Materials | 101 | NULL |
| 2 | Consumer Cyclical | 102 | NULL |
| 3 | Financial Services | 103 | NULL |
| 4 | Real Estate | 104 | NULL |
| 5 | Consumer Defensive | 205 | NULL |
| 6 | Healthcare | 206 | NULL |
| 7 | Utilities | 207 | NULL |
| 8 | Communication Services | 308 | NULL |
| 9 | Energy | 309 | NULL |
| 10 | Industrials | 310 | NULL |
| 11 | Technology | 311 | NULL |
| 12 | Agriculture | 10101 | 101 |
| 13 | Agricultural Inputs | 10101001 | 10101 |
| 14 | Building Materials | 10102 | 101 |
| 15 | Building Materials | 10102002 | 10102 |
| 16 | Chemicals | 10103 | 101 |
| 17 | Chemicals | 10103003 | 10103 |
| 18 | Specialty Chemicals | 10103004 | 10103 |
| 19 | Coal | 10104 | 101 |
| 20 | Forest Products | 10105 | 101 |
| 21 | Lumber & Wood Production | 10105006 | 10105 |
| 22 | Paper & Paper Products | 10105007 | 10105 |
| 23 | Metals & Mining | 10106 | 101 |
| 24 | Aluminum | 10106008 | 10106 |
| 25 | Copper | 10106009 | 10106 |
| 26 | Gold | 10106010 | 10106 |
| 27 | Industrial Metals & Minerals | 10106011 | 10106 |
| 28 | Silver | 10106012 | 10106 |
| 29 | Steel | 10107 | 101 |
| 30 | Coal | 10104005 | 10104 |
したがって、親列には、親 = コードの id 列の値が必要です。私はこれをやろうとしていましたが、自分でこれを理解することはできません。
例えば:
コード列には親列と同じ値があるため、親列に id = 12 の行には値 = 1 が必要です。
手伝ってくれてありがとう!