undefinedfix
Sign in

How does MySQL calculate the number of new users per day?

ifmca edited in Fri, 26 Aug 2022

clipboard.png

I know how to calculate a given day, but I don't know how to calculate the number of new users every day. For example, suppose it's from May 1 to May 30. I hope the final result is:

日期          新增用户数
2019-05-01        10
2019-05-02        0
2019-05-03        10
2019-05-04        10
2019-05-05        10
...
2019-05-30        10
3 Replies
JobsPoker
commented on Fri, 26 Aug 2022

Split into two statements

Number of new users per day:

select date(create_time) d, count(1) from user
where create_time >= '2019-05-01' and create_time <= '2019-05-30'
group by d order by d desc;

Daily orders and users:

select date(create_time) d, count(1), count(distinct user_id) from order
where create_time >= '2019-05-01' and create_time <= '2019-05-30'
group by d order by d desc;
Shweta
commented on Fri, 26 Aug 2022

If you don't keep the number of users added before, how can you check the number of users added 10 days ago?

gjotc
commented on Fri, 26 Aug 2022

You also need to join a date table, otherwise you can't find it without data on that day

lock This question has been locked and the reply function has been disabled.