日期:2014-05-18 浏览次数:20581 次
create table gxsww (begin_date datetime, end_date datetime, sum_value int) insert into gxsww select '2011-01-01', '2011-01-05', 100 union all select '2011-01-08', '2011-01-15', 200 select dateadd(d,b.number,a.begin_date) 'date_value', a.average 'avg_value' from (select begin_date,datediff(d,begin_date,end_date) d, sum_value/(datediff(d,begin_date,end_date)+1) average from gxsww) a inner join master.dbo.spt_values b on b.[type]='P' and b.number between 0 and a.d date_value avg_value ------------ ----------- 2011-01-01 20 2011-01-02 20 2011-01-03 20 2011-01-04 20 2011-01-05 20 2011-01-08 25 2011-01-09 25 2011-01-10 25 2011-01-11 25 2011-01-12 25 2011-01-13 25 2011-01-14 25 2011-01-15 25 (13 row(s) affected)