两个oracle表,一个任务表,一个进度表,通过ID关联,表结构如下:
create table TASK ( ID VARCHAR2(6), PARENTID VARCHAR2(6), NAME VARCHAR2(20), NEW_PROCESS_ID VARCHAR2(6) ) -- Add comments to the columns comment on column TASK.ID is '任务ID'; comment on column TASK.PARENTID is '上级ID'; comment on column TASK.NAME is '任务名称'; comment on column TASK.NEW_PROCESS_ID is '最新进展ID'; create table PROCESS ( ID VARCHAR2(6), TASK_ID VARCHAR2(6), PROCESS INTEGER ) -- Add comments to the columns comment on column PROCESS.ID is '进度ID'; comment on column PROCESS.TASK_ID is '任务ID'; comment on column PROCESS.PROCESS is '进度(%)'; insert into task (ID, PARENTID, NAME, NEW_PROCESS_ID) values ('1', '-1', '顶级任务1', ''); insert into task (ID, PARENTID, NAME, NEW_PROCESS_ID) values ('2', '1', '任务1——1', ''); insert into task (ID, PARENTID, NAME, NEW_PROCESS_ID) values ('3', '1', '任务1——2', '1'); insert into task (ID, PARENTID, NAME, NEW_PROCESS_ID) values ('4', '2', '任务1——1——1', '2'); insert into task (ID, PARENTID, NAME, NEW_PROCESS_ID) values ('5', '2', '任务1——1——2', '3'); insert into task (ID, PARENTID, NAME, NEW_PROCESS_ID) values ('6', '-1', '顶级任务2', ''); insert into task (ID, PARENTID, NAME, NEW_PROCESS_ID) values ('7', '6', '任务2——1', ''); insert into task (ID, PARENTID, NAME, NEW_PROCESS_ID) values ('8', '6', '任务2——2', '4'); insert into process (ID, TASK_ID, PROCESS) values ('1', '3', '30'); insert into process (ID, TASK_ID, PROCESS) values ('2', '4', '40'); insert into process (ID, TASK_ID, PROCESS) values ('3', '5', '50'); insert into process (ID, TASK_ID, PROCESS) values ('4', '8', '60');
现在需要查询出task表的所有数据加上任务进展字段,任务进展方法是具有下级节点的父级任务进展由其所有儿子节点的进度之和除以该父级下所有儿子节点的个数,没有下级节点的叶子节点进度还是进度表中对应值,这样的语句该怎样写?