SQL l连表查询 求大神帮忙看看
select y_num_e,m_num_e,deptname from
(
select sum(re_c.rdlc_num) y_num_e,de.deptname from REPORTVIEWER_count re_c left join hum_list h on re_c.user_id=h.human_sid
inner join department de on de.dept_id=h.dept_id
inner join s_hse_ticket s on s.reghumsid=h.human_sid
where to_char(re_c.create_date,'yyyy')=to_char(sysdate,'yyyy') and s.erifystate='完成' group by re_c.rdlc_num,de.deptname
union all
select sum(re_c.rdlc_num) m_num_e,de.deptname from REPORTVIEWER_count re_c left join hum_list h on re_c.user_id=h.human_sid
inner join department de on de.dept_id=h.dept_id
inner join s_hse_ticket s on s.reghumsid=h.human_sid
where to_char(re_c.create_date,'mm')=to_char(sysdate,'mm') and s.erifystate='完成' group by re_c.rdlc_num,de.deptname
)
如上 报错m_num_e标识符无效 单查询只有字段y_num_e,deptname 原来这样做没出现过这样的问题
请各位大神看看是不是哪写错了
[解决办法]
select y_num_e,m_num_e,deptname from
(
select sum(re_c.rdlc_num) y_num_e,'' as m_num_e,de.deptname from REPORTVIEWER_count re_c left join hum_list h on re_c.user_id=h.human_sid
inner join department de on de.dept_id=h.dept_id
inner join s_hse_ticket s on s.reghumsid=h.human_sid
where to_char(re_c.create_date,'yyyy')=to_char(sysdate,'yyyy') and s.erifystate='完成'
group by re_c.rdlc_num,de.deptname
union all
select '' as y_num_e ,sum(re_c.rdlc_num) m_num_e,de.deptname from REPORTVIEWER_count re_c left join hum_list h on re_c.user_id=h.human_sid
inner join department de on de.dept_id=h.dept_id
inner join s_hse_ticket s on s.reghumsid=h.human_sid
where to_char(re_c.create_date,'mm')=to_char(sysdate,'mm') and s.erifystate='完成'
group by re_c.rdlc_num,de.deptname
)