userid 注册时间
假如就这两个字段
要得到
时间         人数
2009-01-01   0
2009-01-02   10 
2009-01-03    5
2009-01-04    7
表里存的时间是2009-01-01 9:00 000这个类型格式滴
select  count(*),RegisterDate from AccountsInfo ccountsInfo where RegisterDate  BETWEEN '2004/01/01' and '2005/01/01'  group by RegisterDate假如这样写!我就得不到每天的人数!就算哪一天没有人注册那么数据库里就没有这个注册记录  但是我也需要查出这天是0人的记录
希望各位能知道下   如果能给出一个存储过程本人感激不尽   在线等

解决方案 »

  1.   

    select RegisterDate,count(*) from AccountsInfo  where **** group by RegisterDate
      

  2.   


    create proc 存储过程的名称
    参数
    as
    declare @counts intselect  @counts=count(*) from AccountsInfo ccountsInfo 
    where RegisterDate  BETWEEN '2004/01/01' and '2005/01/01'  group by RegisterDateselect @counts
      

  3.   

    没办法的啦,数据库的统计只能帮你这样做,group by 
      

  4.   


    create proc 存储过程的名称
    参数
    as
    declare @counts int
    set @counts=0--刚才少了这一句select  @counts=count(*) from AccountsInfo ccountsInfo 
    where RegisterDate  BETWEEN '2004/01/01' and '2005/01/01'  group by RegisterDateselect @counts
      

  5.   

    唉!还是没有我的答案!但一个朋友帮我搞了个这个sql
    我还是贴出来吧:
    go
    create procedure getDateonlinNumInfo
    (
    @beginDate datetime,
    @endDate datetime
    )
    as
    create table #temp
    (
    daytime datetime
    ) while(@beginDate<=@endDate)
    begin
    insert into #temp values(@beginDate)
    set @beginDate=DATEADD(d,1,@beginDate)
    end
    select a.daytime,count(b.UserID) as counts from #temp as a left join AccountsInfo as b on a.daytime=b.RegisterDate group by a.daytime
    go