我有以下表结构和内容:
+-------------+-----------+------------+
| category_id | parent_id | name |
+-------------+-----------+------------+
| 1 | 0 | Test 1 |
| 2 | 1 | Test 1.1 |
| 3 | 2 | Test 1.1.1 |
| 4 | 0 | Test 2 |
| 5 | 0 | Test 3 |
| 6 | 5 | Test 3.1 |
| 7 | 6 | Test 3.1.1 |
+-------------+-----------+------------+
是否可以编写递归查询以返回结果,如下所示:
+-------------+--------------------------------+
| category_id | path |
+-------------+--------------------------------+
| 1 | Test 1 |
| 2 | Test 1 > Test 1.1 |
| 3 | Test 1 > Test 1.1 > Test 1.1.1 |
| 4 | Test 2 |
| 5 | Test 3 |
| 6 | Test 3 > Test 3.1 |
| 7 | Test 3 > Test 3.1 > Test 3.1.1 |
+-------------+--------------------------------+
谢谢!