私はテーブルを持っています
テーブルDepartments
Id Name Parent
1 Michael Store 0
2 Nonfood 1
3 Clothes 2
4 John Store 0
5 Shoes 2
6 Food 1
7 Men clothes 3
8 Shirts 7
9 Meat 6
10 Food 4
As you see, for each record I have a parent which CAN have it's owen parent. The number of subdivisions is limited to 5. For item 8 (Shirts), you get it's parent (7) which mean that Shirts is part of item with id=7 (Men clothes), part of item with id=3 (Clothes), part of item id=2 (Nonfood), part of id=1 (Michael Store).
I need a Mysql statement with the folowing result:
Id Name Sub1 Sub2 Sub3 Sub4 Sub5
1 Michael Store
2 Michael Store Nonfood
3 Michael Store Nonfood Clothes
4 John Store
5 Michael Store Nonfood Shoes
6 Michael Store Food
7 Michael Store Nonfood Clothes Men clothes
8 Michael Store Nonfood Clothes Men clothes Shirts
9 Michael Store Food Meat
10 John Store Food
お時間をいただきありがとうございます!