|
2 个sql
select
b.cust_group_id group_id,
avg(case when a.cust_age >0 then a.cust_age end) avg_age,
sum(a.now_talk_am)/count(b.cust_id) now_talk_am_cust,
sum(a.now_talk)/count(b.cust_id) now_talk_cust,
sum(a.now_arpu)/count(b.cust_id) now_income_cust,
sum(a.pre_m_talk_am)/count(b.cust_id) pre_m_talk_am_cust,
sum(a.pre_m_talk)/count(b.cust_id) pre_m_talk_cust,
sum(a.pre_m_arpu)/count(b.cust_id) pre_m_income_cust,
sum(a.pre_m_arpu) income,
sum(c.m) m,
sum(c.m)/count(b.cust_id) m_cust,
case when count(case when a.cust_sex='女' then b.cust_id end) =0 then null else
cast(count(case when a.cust_sex='男' then b.cust_id end) as decimal(16,2))/count(case when a.cust_sex='女' then b.cust_id end) end sex_r
from CUST_CHURN_INFO_200710 a
inner join CUST_CCP_INFO_200710 c on c.cust_id=b.cust_id
inner join PAR_CUST_CUST_GRP_ASSOC_200710 b on a.cust_id=b.cust_id
group by b.cust_group_id;
和
select
b.cust_group_id group_id,
avg(case when a.cust_age >0 then a.cust_age end) avg_age,
sum(a.now_talk_am)/count(b.cust_id) now_talk_am_cust,
sum(a.now_talk)/count(b.cust_id) now_talk_cust,
sum(a.now_arpu)/count(b.cust_id) now_income_cust,
sum(a.pre_m_talk_am)/count(b.cust_id) pre_m_talk_am_cust,
sum(a.pre_m_talk)/count(b.cust_id) pre_m_talk_cust,
sum(a.pre_m_arpu)/count(b.cust_id) pre_m_income_cust,
sum(a.pre_m_arpu) income,
sum(c.m) m,
sum(c.m)/count(b.cust_id) m_cust,
case when count(case when a.cust_sex='女' then b.cust_id end) =0 then null else
cast(count(case when a.cust_sex='男' then b.cust_id end) as decimal(16,2))/count(case when a.cust_sex='女' then b.cust_id end) end sex_r
from CUST_CHURN_INFO_200709 a
inner join CUST_CCP_INFO_200709 c on c.cust_id=b.cust_id
inner join PAR_CUST_CUST_GRP_ASSOC_200709 b on a.cust_id=b.cust_id
group by b.cust_group_id; |
|