MySQL 利用时间(秒分时日月年)分组统计

1.统计 七天 前 人数
select count(*) from your_table where last_login_time> date_sub(date(now()), interval 7 day);
date_add
2.按天累计人数
select DATE_FORMAT(last_login_time, '%Y-%m-%d') as dd, count(*) as '每日' from your_table group by dd order by dd desc;
3.按月统计
select DATE_FORMAT(last_login_time, '%Y-%m') as dd, count(*) as '每月' from your_table group by dd order by dd desc;

posted @ 2022-03-18 18:15  迷茫的小白  阅读(249)  评论(0)    收藏  举报