my query is:
select region_id,product_id,contract_type_id,no_of_mon,
count (case when no_of_mon=1 then cust_cod end),
count (case when no_of_mon=1 and c_type='P' then cust_cod end),
count (case when no_of_mon=1 and c_type='N' then cust_cod end),
0 as others from churn1 where no_of_mon=1 group by region_id,product_id,contract_type_id,no_of_mon;
by using this query i can dig the values for month 1. i need a query which can dig the values for 1 to 12 months.
i construct a query
select c.region_id,c.product_id,c.contract_type_id,c.no_of_mon,
count (case when c.no_of_mon=m.no_of_mon then cust_cod end) as total,
count (case when c.no_of_mon=m.no_of_mon and c_type='P' then cust_cod end) as prepaid,
count (case when c.no_of_mon=m.no_of_mon and c_type='N' then cust_cod end) as postpaid,
0 as others from churn1 c,month m where c.no_of_mon=m.no_of_mon group by c.region_id,c.product_id,c.contract_type_id,c.no_of_mon;
is it rite or is there any other way to optimize it