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;

  

原文地址:https://www.cnblogs.com/start-fxw/p/5909445.html