标题: Oracle使用count和case when配合统计 [打印本页]
作者: xiexie 时间: 2022-6-28 14:57 标题: 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
欢迎光临 PHP开发笔记 (http://phpvi.com/) |
Powered by Discuz! 6.1.0 |