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;

posted @   lily_z  阅读(5884)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示