发新话题
打印

Oracle使用count和case when配合统计

Oracle使用count和case when配合统计

select 
to_char(t.addtime, 'yyyy-mm') as curDate,
count(distinct(t.uuid)) 新注册,
count(distinct case when t.operateid = 1111 then t.uuid else null end) as 新付费用户数,
sum(case when (t.operateid = 1007 or t.operateid = 1005) then t.operatevalue-t.promotevalue else 0 end)/100 as 当月充值金额
from table1 t 
where t.operateid in(1005,1007,1111)  and t.errorcode=0 
and  t.addtime>=to_date('2022-01','yyyy-mm')
and t.uuid in (select t1.uuid from table2 t1 where to_char(t1.addtime, 'yyyy-mm') = to_char(t.addtime, 'yyyy-mm')) 
group by to_char(t.addtime, 'yyyy-mm') 
order by curDate

TOP

发新话题