利用层次查询: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;
解决方案 »
- ORACLE分区问题求教
- SQl模糊查询优化 具有天才的疯子称号的高手进
- 求会oracle和mysql的大神,帮我把下面的oracle语句用mysql语句来表达!
- 请教Toad工具如何实现类型plsql中的for update操作
- 这条查询语句 oracle 是如何分析执行的?
- swing通过jdbc方式连接oracle10无法连接上
- 请教一个关于触发器执行的简单问题
- 关于表嵌套分区的问题?up有分。
- 无法进入Oracle!-在线请教
- http://otn.oracle.com/documentation里面的文章怎样才能看啊?
- Aix 4.3 下安装 oracle817 求助
- 求:Oracle事务处理比较完整的一个例子
wait...
我试了一下,如果你在Team_count列中保存所有Name的值,只有做函数,在select中调用,如果只要保存个数,则可以用count统计有多少个下级。
其中Parent_id 为ID的上级ID,
现向针对每一个ID,统计出其下级数量,
并将ID及相应的统计值写入另一表(字段:ID,Team_count)中.