统计用户注册人数(7天日期)


		SELECT
        date_add( curdate(), INTERVAL ( cast( help_topic_id AS signed INTEGER ) - 7 ) DAY ) time,ifnull( am.count, 0 ) total
        FROM mysql.help_topic h
        LEFT JOIN (
        	SELECT
        	date_format( created_at, '%Y-%m-%d' ) time,
        	count( 0 ) count
        	FROM
        	user_detail
        	GROUP BY
        	date_format( created_at, '%Y-%m-%d' )
        ) am ON date_add( curdate(), INTERVAL ( cast( h.help_topic_id AS signed INTEGER ) - 7 ) DAY ) = am.time
        WHERE h.help_topic_id <= 7 ORDER BY h.help_topic_id
        
		其中mysql.help_topic为系统表,主要的业务表为user_detail(用户详情表)
SELECT
    DATE_FORMAT( t1.date, '%Y-%m-%d' ) AS date,
    IFNULL( t2.num, 0 ) AS registerNum
FROM
    (SELECT
        @i := @i + 1 AS 'NO',
        DATE(
        DATE_ADD( '2021-11-20', INTERVAL @i DAY )) AS date     -- 开始时间[创建日期表]
    FROM
        mysql.help_topic,
        ( SELECT @i := - 1 ) t
    WHERE
    @i < DATEDIFF( '2021-12-30', '2021-11-20' )) t1                -- 结束时间,开始时间
LEFT JOIN
    (SELECT
        DATE( CreateTime ) AS date,
        COUNT( 1 ) AS num
    FROM
        USER
    WHERE
        CreateTime >= '2021-11-20' ) t2 ON t1.date = t2.date  -- 开始时间[联表查询]]
GROUP BY date
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值