create materialized view wholeTaskStatistics refresh on demand with rowid start with
to_date('20161222','yyyymmdd')next sysdate+10/(24*60) as
select a.departmentname ,sum(NVL(a.sum,0)),sum(NVL(SEASONNOTCHECKSUM,0))SEASONNOTCHECKSUM,sum(NVL(BIGPROBLEMSUM,null))BIGPROBLEMSUM,sum(NVL(SOLVEPROBLEMSUM,0))SOLVEPROBLEMSUM
from(
select a.departmentname,a.departmentcode,a.sum, b.SEASONNOTCHECKSUM, c.BIGPROBLEMSUM ,d.SOLVEPROBLEMSUM
from(select d.departmentname,d.departmentcode, count(*)sum
from tbldepartment d,tbluserinfo u,tbldepartment_user du,client_check_c_task ct
where d.departmentcode=du.departmentcode and u.workid=du.userid
and u.workid=ct.checker_userid
group by d.departmentcode, d.departmentname)a left join
(select d.departmentname,d.departmentcode, count(*)SEASONNOTCHECKSUM from
tbldepartment d,tbluserinfo u,tbldepartment_user du,client_check_c_task ct
where d.departmentcode=du.departmentcode and u.workid=du.userid
and u.workid=ct.checker_userid and ct.status!=5
and ct.create_time>= trunc(sysdate,'Q') and ct.create_time<add_months(trunc(sysdate,'Q'),3)-1
group by d.departmentcode, d.departmentname
) b on a.departmentcode=b.departmentcode and a.departmentname=b.departmentname
left join
(select d.departmentname,d.departmentcode, count(*) BIGPROBLEMSUM from
tbldepartment d,tbluserinfo u,tbldepartment_user du,client_check_c_task ct
where d.departmentcode=du.departmentcode and u.workid=du.userid
and u.workid=ct.checker_userid and ct.is_big_problem=1
group by d.departmentcode, d.departmentname
) c on b.departmentcode=c.departmentcode and b.departmentname=c.departmentname
left join
(select d.departmentname,d.departmentcode ,count(*)SOLVEPROBLEMSUM from
tbldepartment d,tbluserinfo u,tbldepartment_user du,client_check_c_task ct
where d.departmentcode=du.departmentcode and u.workid=du.userid
and u.workid=ct.checker_userid
and ct.is_big_problem=1 and ct.is_solve_problem=1
group by d.departmentcode, d.departmentname
)d on c.departmentcode=d.departmentcode and c.departmentname=d.departmentname
union
select a.departmentname,a.departmentcode,a.sum, b.SEASONNOTCHECKSUM, c.BIGPROBLEMSUM ,d.SOLVEPROBLEMSUM
from(select d.departmentname,d.departmentcode, count(*)sum
from tbldepartment d,tbluserinfo u,tbldepartment_user du,client_check_p_task ct
where d.departmentcode=du.departmentcode and u.workid=du.userid
and u.workid=ct.checker_userid
group by d.departmentcode, d.departmentname)a left join
(select d.departmentname,d.departmentcode, count(*)SEASONNOTCHECKSUM from
tbldepartment d,tbluserinfo u,tbldepartment_user du,client_check_p_task ct
where d.departmentcode=du.departmentcode and u.workid=du.userid
and u.workid=ct.checker_userid and ct.status!=5
and ct.create_time>= trunc(sysdate,'Q') and ct.create_time<add_months(trunc(sysdate,'Q'),3)-1
group by d.departmentcode, d.departmentname
) b on a.departmentcode=b.departmentcode and a.departmentname=b.departmentname
left join
(select d.departmentname,d.departmentcode, count(*) BIGPROBLEMSUM from
tbldepartment d,tbluserinfo u,tbldepartment_user du,client_check_p_task ct
where d.departmentcode=du.departmentcode and u.workid=du.userid
and u.workid=ct.checker_userid and ct.is_big_problem=1
group by d.departmentcode, d.departmentname
) c on b.departmentcode=c.departmentcode and b.departmentname=c.departmentname
left join
(select d.departmentname,d.departmentcode ,count(*)SOLVEPROBLEMSUM from
tbldepartment d,tbluserinfo u,tbldepartment_user du,client_check_p_task ct
where d.departmentcode=du.departmentcode and u.workid=du.userid
and u.workid=ct.checker_userid
and ct.is_big_problem=1 and ct.is_solve_problem=1
group by d.departmentcode, d.departmentname
)d on c.departmentcode=d.departmentcode and c.departmentname=d.departmentname
) a group by a.departmentcode, a.departmentname