表结构如下:
good_id, good_name, parent_id(父id)
1, a, 0
2, b, 0
3, a2_0, 1
4, a2_1, 1
5, a2_0_0, 3
select distinct e.good_id,e.good_name,e.parent_id
from cms_good a
inner join cms_good b on a.good_id=b.parent_id or a.good_id=b.good_id
inner join cms_good c on b.good_id=c.parent_id or b.good_id=c.good_id
inner join cms_good d on c.good_id=d.parent_id or c.good_id=d.good_id
inner join cms_good e on d.good_id=e.parent_id or d.good_id=e.good_id
where a.good_id=2