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;
tabletime3. 统计表TABLE_NAME中以字段START_TIME为参照,共多少天数据,多少条数据
select to_days(now()) - to_days(min(START_TIME)) as days, count(*) from TABLE_NAME;
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论