select comp_id,
(select dept_name from p_dept where p_dept.dept_id=comp_id) comp_name,
count(distinct serv_id),sum(fact_fee)/100,sum(months)--第四部
from tmp_adsl_charge_201203 --第一步
where oper_type_id='03040401' --第二步
group by comp_id,2 --第三步
order by 1,2;--第五步
(select dept_name from p_dept where p_dept.dept_id=comp_id) comp_name,
count(distinct serv_id),sum(fact_fee)/100,sum(months)--第四部
from tmp_adsl_charge_201203 --第一步
where oper_type_id='03040401' --第二步
group by comp_id,2 --第三步
order by 1,2;--第五步
(select dept_name
from p_dept
where p_dept.dept_id=comp_id) 'comp_name', -- 3
count(distinct serv_id), -- 3
sum(fact_fee)/100, -- 3
sum(months) -- 3
from tmp_adsl_charge_201203
where oper_type_id='03040401' -- 1
group by comp_id,2 -- 2
order by 1,2 -- 4