create table dd(id varchar(8),time datetime,money money,job varchar(100)) insert into dd select 'bfbumen01','2011-03-14','12454.214','电子商务' union all select 'bfbumen01','2011-03-14','12454.214','电子商务' union all select 'bfbumen02','2011-03-15','12454.214','电子商务' union all select 'bfbumen03','2011-03-15','12454.214','电子商务' union all select 'bfbumen01','2011-03-16','12454.214','电子商务' union all select 'bfbumen02','2011-03-16','12454.214','电子商务' union all select 'bfbumen01','2011-03-17','12454.214','电子商务' union all select 'bfbumen02','2011-03-17','12454.214','电子商务' union all select 'bfbumen03','2011-03-17','12454.214','电子商务' union all select 'bfbumen01','2011-03-18','12454.214','电子商务' union all select 'bfbumen02','2011-03-18','12454.214','电子商务' union all select 'bfbumen03','2011-03-19','12454.214','电子商务' union all select 'bfbumen02','2011-03-19','12454.214','电子商务' union all select 'bfbumen01','2011-03-19','12454.214','电子商务' union all select 'bfbumen01','2011-03-20','12454.214','电子商务' union all select 'bfbumen01','2011-03-21','12454.214','电子商务' union all select 'bfbumen03','2011-03-21','12454.214','电子商务' union all select 'bfbumen01','2011-03-22','12454.214','电子商务' union all select 'bfbumen02','2011-03-22','12454.214' ,'电子商务'union all select 'bfbumen03','2011-03-22','12454.214','电子商务' union all select 'bfbumen01','2011-03-18','12454.214','电子商务' union all 有很多岗位,id 为员工工号,想得到的结果:以每星期一为一周统计时间,(统计人数用 count(*) 想要的结果(结果只是个例子,不是正确的数据): 人数 时间 钱 岗位 23 2011-03-14 22152252.54 电子商务 23 2011-03-21 22152252.54 电子商务 23 2011-03-28 22152252.54 电子商务 。。。
------解决方案--------------------
SQL code
select count(1), min(time), sum(money), job from dd group by datediff(day,0,time)/7, job
------解决方案-------------------- 顺便问下 楼主准备以哪个时间作为统计开始时间
------解决方案--------------------