SQL练习笔记——统计每日的新充用户数,新提用户人数,新用户充提比

表中包含信息如下,统计每日的新充用户数,新提用户人数,新用户充提比

字段说明:statics_date:统计日期,channel:渠道,desc:描述,registerTime:用户注册时间,uid:用户ID,registerip:注册IP

解题思路

#1.查询出每天的新充用户人数和新提用户人数(充值日期=注册日期,提现日期=注册日期)

利用 count(distinct + case when)

select statics_date as 日期,
count(distinct case when `desc` ='充值' and date(registerTime) = statics_date then uid end) as 新充用户人数,
count(distinct case when `desc` ='提现' and date(registerTime) = statics_date then uid end) as 新提用户人数
from record
group by 日期;

#2.计算新用户充提比(新用户当日提现人数/新用户当日充值人数)

with 每日统计 as
(select statics_date as 日期,
count(distinct case when `desc` ='充值' and date(registerTime) = statics_date then uid end) as 新充用户人数,
count(distinct case when `desc` ='提现' and date(registerTime) = statics_date then uid end) as 新提用户人数
from record
group by 日期
)
select *,concat(round((新提用户人数/新充用户人数),2)*100,'%')  as 新用户充提比
from 每日统计;

输出结果:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值