SQL 按天统计,按月统计和统计天数
确定要统计的时间字段,例句中为start_time
1. 从表TABLE_NAME中以字段START_TIME为参照,按天统计
select START_TIME, DATE_FORMAT(START_TIME,'%Y-%m-%d') as day, count(*) as sum from TABLE_NAME group by day;
2. 从表TABLE_NAME中以字段START_TIME为参照,按月统计
select START_TIME, DATE_FORMAT(START_TIME,'%Y-%m') as month, count(*) as sum from TABLE_NAME group by month;
3. 统计表TABLE_NAME中以字段START_TIME为参照,共多少天数据,多少条数据
select to_days(now()) - to_days(min(START_TIME)) as days, count(*) from TABLE_NAME;
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步