版本:mysql 8.0.33 ,我能查到结果,楼主什么数据都查不出来吗?
mysql> WITH RECURSIVE company_tree AS (
-> SELECT id, companyname, parent
-> FROM tb_company_info
-> WHERE companyname = 'top'
-> UNION ALL
-> SELECT
c.id, c.companyname, c.parent
-> FROM tb_company_info c
-> INNER JOIN company_tree ct ON ct.companyname = c.parent
-> )
-> SELECT *
-> FROM company_tree;
+------+---------------+----------+
| id | companyname | parent |
+------+---------------+----------+
| 513 | top | |
| 490 | MR98C-B1 | top |
| 491 | MR98E-B1 | top |
| 492 | MR98E-B1-V101 | MR98E-B1 |
+------+---------------+----------+