select min(日期) into #t from yourtable
declare @d datetime
select @d = min(日期) from yourtable
while exists (select * from yourtable where 日期 > @d)
begin
  set @d = dateadd(day, 1, @d)
  insert #t select @d
end
select A.日期, sum(B.销售额) from #t A left join yourtable B
on A.日期 = B.日期 group by A.日期

解决方案 »

  1.   

    select min(日期) 日期 into #t from yourtable
    declare @d datetime
    select @d = min(日期) from yourtable
    while exists (select * from yourtable where 日期 > @d)
    begin
      set @d = dateadd(day, 1, @d)
      insert #t select @d
    end
    select A.日期, isnull(sum(B.销售额),0) from #t A left join yourtable B
    on A.日期 = B.日期 group by A.日期
      

  2.   

    declare @min datetime,@max datetime
    select @min=min(日期),@max=max(日期) from [table]select top 365 identity(int,0,1) num into # from sysobjects,sysobjects a
    select a.mydate 日期,isnull(sum(b.销售额),0) 销售额 from 
    (select dateadd(day,num,@min) mydate from # where dateadd(day,num,@min)<=@max) a
    left join [table] b on a.mydate=b.日期 group by a.mydate
      

  3.   

    declare @min datetime,@max datetime
    select @min=min(日期),@max=max(日期) from [table]select top 365 identity(int,0,1) num into # from sysobjects,sysobjects a
    select a.mydate 日期,isnull(sum(b.销售额),0) 销售额 from # a
    left join [table] b on a.NUM+@Min=b.日期 
    where a.Num+@min<@Max
    group by a.Num+@min