select avg(Cnt) from (
select day(Time) as Day1,count(1) as Cnt from tab where 
convert(varchar(7),Time,120)=convert(varchar(7),Getdate(),120)
group by day(Time)
) as t

解决方案 »

  1.   

    select avg()
    from t
    group by convert(char(10),dcol,120)
      

  2.   


    select avg(a.count1) from (
    select day(time1) day1,count(1) as count1 from table 
    where datediff(month,time1,getdate())=0
    group by day(time1)
    ) a
      

  3.   


    --先得出本月有多少天
    declare @count int
    if(datepart(mm,getdate())<12)
        set @count=datediff(dd,convert(varchar(7),getdate(),120)+'-01',convert(varchar(7),dateadd(mm,1,getdate()),120)+'-01')
    else 
        set @count=datediff(dd,convert(varchar(7),getdate(),120)+'-01',datename(yy,dateadd(yy,1,getdate()))+'-01-01') ----本月平均每天新增记录的数量
    select count(1)*1.0/@count from 表名 where datediff(mm,时间字段,getdate())=0
      

  4.   

    怎样统计出12月,那天添加的记录最多。select top 1 convert(varchar(10),日期,120) 日期 , count(*) cnt from tb group by convert(varchar(10),日期,120) order by cnt desc