首页 > 技术文章 > MySql sql按时间分组

start-fxw 2016-09-26 15:46 原文

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;

  

推荐阅读