利用层次查询:format org_chart format a20SELECT LPAD(' ',2*(LEVEL-1)) || name org_chart,id,parent_id
FROM table_name
START WITH Parent_id is null
CONNECT BY PRIOR id = parent_id;其中level为当前层次数的伪列,也可以查询出来SELECT level,LPAD(' ',2*(LEVEL-1)) || name org_chart,id,parent_id
FROM table_name
START WITH Parent_id is null
CONNECT BY PRIOR id = parent_id;
FROM table_name
START WITH Parent_id is null
CONNECT BY PRIOR id = parent_id;其中level为当前层次数的伪列,也可以查询出来SELECT level,LPAD(' ',2*(LEVEL-1)) || name org_chart,id,parent_id
FROM table_name
START WITH Parent_id is null
CONNECT BY PRIOR id = parent_id;
wait...
我试了一下,如果你在Team_count列中保存所有Name的值,只有做函数,在select中调用,如果只要保存个数,则可以用count统计有多少个下级。
其中Parent_id 为ID的上级ID,
现向针对每一个ID,统计出其下级数量,
并将ID及相应的统计值写入另一表(字段:ID,Team_count)中.