求大神解答
CREATE or REPLACE view view_REPORTVIEWER_count_type as --创建视图view_REPORTVIEWER_count_type
select y_num_e,m_num_e,d_num_e,m_num_s,y_num_zf,m_num_zf,r_title from
(
--年-完成
select distinct a.r_title,b.rdlc_num y_num_e,null m_num_e,null d_num_e,null m_num_s,null y_num_zf,null m_num_zf
from REPORTVIEWER a
inner join
(select sum(rdlc_num) as rdlc_num,rdlc_id,user_id from REPORTVIEWER_count d
where to_char(d.create_date,'yyyy')=to_char(sysdate,'yyyy') group by rdlc_id,user_id) b
on b.rdlc_id=a.sid
inner join s_hse_ticket e on e.reghumsid=b.user_id
where e.erifystate='完成'
union all
--月-完成
select distinct a.r_title,null y_num_e,b.rdlc_num m_num_e,null d_num_e,null m_num_s,null y_num_zf,null m_num_zf
from REPORTVIEWER a
inner join
(select sum(rdlc_num) as rdlc_num,rdlc_id,user_id from REPORTVIEWER_count d
where to_char(d.create_date,'mm')=to_char(sysdate,'mm') group by rdlc_id,user_id) b
on b.rdlc_id=a.sid
inner join s_hse_ticket e on e.reghumsid=b.user_id
where e.erifystate='完成'
union all
--日-完成
select distinct a.r_title,null y_num_e,null m_num_e,b.rdlc_num d_num_e,null m_num_s,null y_num_zf,null m_num_zf
from REPORTVIEWER a
inner join
(select sum(rdlc_num) as rdlc_num,rdlc_id,user_id from REPORTVIEWER_count d
where to_char(d.create_date,'dd')=to_char(sysdate,'dd') group by rdlc_id,user_id) b
on b.rdlc_id=a.sid
inner join s_hse_ticket e on e.reghumsid=b.user_id
where e.erifystate='完成'
union all
--作业中
select distinct a.r_title,null y_num_e,null m_num_e,null d_num_e,b.rdlc_num m_num_s,null y_num_zf,null m_num_zf
from REPORTVIEWER a
inner join
(select sum(rdlc_num) as rdlc_num,rdlc_id,user_id from REPORTVIEWER_count d
where to_char(d.create_date,'mm')=to_char(sysdate,'mm') group by rdlc_id,user_id) b
on b.rdlc_id=a.sid
inner join s_hse_ticket e on e.reghumsid=b.user_id
where e.erifystate='申请'
union all
--年-作废
select distinct a.r_title,null y_num_e,null m_num_e,null d_num_e,null m_num_s,b.rdlc_num y_num_zf,null m_num_zf
from REPORTVIEWER a
inner join
(select sum(rdlc_num) as rdlc_num,rdlc_id,user_id from REPORTVIEWER_count d
where to_char(d.create_date,'yyyy')=to_char(sysdate,'yyyy') group by rdlc_id,user_id) b
on b.rdlc_id=a.sid
inner join s_hse_ticket e on e.reghumsid=b.user_id
where e.erifystate='作废'
union all
--月-作废
select distinct a.r_title,null y_num_e,null m_num_e,null d_num_e,null m_num_s,null y_num_zf,b.rdlc_num m_num_zf
from REPORTVIEWER a
inner join
(select sum(rdlc_num) as rdlc_num,rdlc_id,user_id from REPORTVIEWER_count d
where to_char(d.create_date,'mm')=to_char(sysdate,'mm') group by rdlc_id,user_id)&nb