--假设以'2007-01-08'开始
declare @t table(ID int, name varchar(10), CountedTime datetime, aCount real)
insert @t
select 1, '张三', '2007-01-05', 100 union all
select 1, '张三', '2007-01-08', 200 union all
select 1, '张三', '2007-01-12', 300 union all
select 1, '张三', '2007-01-20', 400 union all
select 1, '张三', '2007-01-23', 500 union all
select 1, '张三', '2007-01-31', 600 union all
select 1, '张三', '2007-02-02', 700 union all
select 1, '张三', '2007-02-05', 800
select
id,name,
beginday=min(dateadd(wk,datediff(wk, '2007-01-08', CountedTime),'2007-01-08')),
endtday=min(dateadd(day,6,dateadd(wk,datediff(wk, '2007-01-08', CountedTime),'2007-01-08'))),
sumCount=sum(aCount)
from
@t
where
CountedTime >= '2007-01-08'
group by
id,name,datepart(week,CountedTime)