MySql sql按时间分组

select   DATE_FORMAT(f.upload_time,'%Y%u') weeks,count(*),sum(p.download_times),sum(p.collection_times),sum(p.click_times)    from file_base f left join file_property p on f.property_id = p.id   group by weeks;

select   DATE_FORMAT(f.upload_time,'%Y-%m-%d') days,count(*),sum(p.download_times),sum(p.collection_times),sum(p.click_times)
	from file_base f left join file_property p on f.property_id = p.id  group by days;

select   DATE_FORMAT(f.upload_time,'%Y%m') months,count(*),sum(p.download_times),sum(p.collection_times),sum(p.click_times) from file_base f left join file_property p on f.property_id = p.id   group by months;

  

posted @ 2016-09-26 15:46  start逍遥  阅读(7718)  评论(0编辑  收藏  举报