一条SQL统计每天的用户注册、注销数

该SQL查询用于统计2022年6月1日至7月30日期间,每天的用户注册和注销数量。通过全连接查询从user表中分别获取注册(CREATE_TIME)和注销(logout_time,非空)数据,然后按日期进行聚合,确保即使某天没有数据也会显示为0。结果按日期降序排列。
摘要由CSDN通过智能技术生成
通过表中记录的注册、注销时间,按日期统计每天的注册、注销数量:
select * from (
    select 
    ​​​​​​​NVL(v1.register_count,0) register_count,
    NVL(v2.logout_count,0) logout_count,
    NVL(v1.count_date,v2.count_date) count_date
    from (select count(*) as register_count, trunc(CREATE_TIME) as count_date from user
            group by trunc(CREATE_TIME)) v1
    full join (select count(*) as logout_count, trunc(logout_time) as count_date from user
               where logout_time is not null group by trunc(logout_time)) v2
        on v1.count_date = v2.count_date
)
where count_date between to_date('2022-06-01 00:00:00','yyyy-MM-dd HH24:mi:ss')
          and to_date('2022-07-30 00:00:00','yyyy-MM-dd HH24:mi:ss')
order by v1.count_date desc;

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值