我有 2 张桌子:
1. Team
id group_head initial_team
id : for id table (auto increment)
Group Head : employee id to add group head
initial team : initial team for this team
2. Team Sub
id team_id employee_id parent parent_id
id : id for table (auto increment)
team_id : id of the Team_table
employee_id : employee id
parent : value 0 if they child from team_sub, value 1 if they child from team
parent_id : if parent value 1 the parent id is id team, if parent value 0 the parent is id team sub
我的问题:如何知道团队(组长)的孩子总数?或者如何知道id team的底层孩子?如果我删除 id team 孩子也会被删除..
例子 :
id team : 1
data from team_ sub :
status parent: 1 parent_id : 1 (id this data is 1)
status parent: 0 parent_id : 1 (id this data is 2)
status parent: 0 parent_id : 2 (id this data is 3)
status parent: 0 parent_id : 3 (id this data is 4)
status parent: 0 parent_id : 4 (id this data is 5)
id team : 2
data from team_ sub :
status parent: 1 parent_id : 2 (id this data is 6)
status parent: 0 parent_id : 6 (id this data is 7)
status parent: 0 parent_id : 7 (id this data is 8)
status parent: 0 parent_id : 8 (id this data is 9)
status parent: 0 parent_id : 9 (id this data is 10)
其中父状态为 1,parent_id 为 id team..
父状态为 0,parent_id 为 id team_sub..
这是图像上的关系数据,
如果我的英语不好,抱歉...
id team_sub 10 是 id team 2 的孩子,id team_sub 5 是 id team 1 的孩子。