日期:2014-05-16 浏览次数:20828 次
create TABLE t10( branch_id INT(11), flow_total INT(11), flow_free INT(11), flow_nofree INT(11) , effect_time datetime); insert into t10 values (1,256,128,128,'2010-09-10 00:00:00'), (1,1024,256,768,'2010-09-10 00:05:00'), (2,1024,256,768,'2010-09-10 00:00:00'), (2,1024,256,768,'2010-09-10 00:05:00'); select * from t10; # 日 select branch_id,sum(flow_total),sum(flow_free),sum(flow_nofree),date_format(effect_time,'%Y-%m-%d') from t10 group by branch_id,date_format(effect_time,'%Y-%m-%d'); # 周 select branch_id,sum(flow_total),sum(flow_free),sum(flow_nofree),yearweek(effect_time) from t10 group by branch_id,yearweek(effect_time); # 月 select branch_id,sum(flow_total),sum(flow_free),sum(flow_nofree),date_format(effect_time,'%Y-%m') from t10 group by branch_id,date_format(effect_time,'%Y-%m'); # 年 select branch_id,sum(flow_total),sum(flow_free),sum(flow_nofree),date_format(effect_time,'%Y') from t10 group by branch_id,date_format(effect_time,'%Y');