select 
  isnull (a.nday,b.nday) as nday,
  isnull (b.num,0 ) as num(
select nday from lm group by nday) a full join (
SELECT nday,count(*) as num FROM lm GROUP BY nday
) b
on a.nday=b.nday

解决方案 »

  1.   

    --创建一个表
    create #tmp
    (
        [time] datetime
    )--输入连续的日期
    declare @i int
    set @i = 100
    while @i > 0
    begin
        insert into #tmp select dateadd(day,@i,'2004/05/06')
    end --输出
    select [time],count(id) from ( select [time],id from 表 union all select [time],null as ID from #tmp ) tdrop table #tmp哈哈,方法比较笨~~。
      

  2.   

    declare @dt datetime,@i int
    select @dt=min(nday),@i=datediff(day,max(nday),min(nday))+1
    from lm
    if @@rowcount=0 returnset rowcount @i
    select id=identity(int,0,1),a=0 into #t from syscolumns a,syscolumns b
    set @i=@i-@@rowcount
    while @i>0
    begin
    set rowcount @i
    insert #t select 0 from syscolumns a,syscolumns b
    set @i=@i-@@rowcount
    end
    set rowcount 0select nday=dateadd(day,a.id,@dt),[count]=isnull(b.[count],0)
    from #t a left join(
    SELECT nday,[count]=count(*) FROM lm GROUP BY nday
    )b on a.id=datediff(day,@dt,b.nday)drop table #t
      

  3.   

    --创建一个表
    create #tmp
    (
        [time] datetime
    )--输入连续的日期
    declare @i int
    set @i = 100
    while @i > 0
    begin
        insert into #tmp select dateadd(day,@i,'2004/05/06')
        set @i = @i - 1
    end --输出
    select [time],count(id) from ( select [time],id from 表 union all select [time],null as ID from #tmp ) t group by [time]drop table #tmp哈哈,方法比较笨~~。