select t3.manager, max(case t1.cust_type when '01' then t1.cust_typeC else 0 End) a, max(case t1.cust_type when '02' then t1.cust_typeC else 0 End) b, max(case t1.cust_type when '03' then t1.cust_typeC else 0 End) c, max(case t2.cust_belong when '01' then t2.cust_belongC else 0 End) d, max(case t2.cust_belong when '02' then t2.cust_belongC else 0 End) e, max(case t2.cust_belong when '03' then t2.cust_belongC else 0 End) x from (select m.manager , m.cust_type , count(1) cust_typeC from b_customer_base_info_t m group by m.manager , m.cust_type) t1, (select m.manager , m.cust_belong , count(1) cust_belongC from b_customer_base_info_t m group by m.manager ,m.cust_belong) t2, (select m.manager from b_customer_base_info_t m group by m.manager ) t3 where t3.manager = t1.manager and t3.manager = t2.manager group by t3.manager
t3.manager,
max(case t1.cust_type when '01' then t1.cust_typeC else 0 End) a,
max(case t1.cust_type when '02' then t1.cust_typeC else 0 End) b,
max(case t1.cust_type when '03' then t1.cust_typeC else 0 End) c,
max(case t2.cust_belong when '01' then t2.cust_belongC else 0 End) d,
max(case t2.cust_belong when '02' then t2.cust_belongC else 0 End) e,
max(case t2.cust_belong when '03' then t2.cust_belongC else 0 End) x
from
(select m.manager , m.cust_type , count(1) cust_typeC from b_customer_base_info_t m group by m.manager , m.cust_type) t1,
(select m.manager , m.cust_belong , count(1) cust_belongC from b_customer_base_info_t m group by m.manager ,m.cust_belong) t2,
(select m.manager from b_customer_base_info_t m group by m.manager ) t3
where t3.manager = t1.manager
and t3.manager = t2.manager
group by t3.manager