SELECT distinct CONVERT(char(10), Dt,126) as '统计时间',sum([F_REGCOUNT]) as '注册量'
FROM [Datagram].[dbo].[RegisterCount] with(nolock)
where CONVERT(char(10), Dt,126) between '2013-05-01' and '2013-05-04'
group by CONVERT(char(10), Dt,126)
order by CONVERT(char(10), Dt,126)SELECT distinct CONVERT(char(10), Dt,126) as '统计时间'
      ,[MaxOnline] as '最高在线'
      ,[AvgOnline] as '平均在线'
  FROM [Datagram].[dbo].[DayOnlineCount] with(nolock)
where CONVERT(char(10), Dt,126) between '2013-05-01' and '2013-05-04'
select distinct CONVERT(char(10), F_TIME,126) as '统计时间',
F_BACKNUM as '返回人数' from REPORT.DBO.USERNUM
where CONVERT(char(10), F_TIME,126) between '2013-05-01' and '2013-05-04'
根据日期范围查询, 编写一个存储过程,
返回结果为 "统计时间" '注册量' '最高在线' '平均在线' '返回人数'求高手赐教~

解决方案 »

  1.   


    select * from 
    (
    SELECT distinct CONVERT(char(10), Dt,126) as '统计时间',sum([F_REGCOUNT]) as '注册量'
    FROM [Datagram].[dbo].[RegisterCount] with(nolock)
    where CONVERT(char(10), Dt,126) between '2013-05-01' and '2013-05-04'
    group by CONVERT(char(10), Dt,126)
    order by CONVERT(char(10), Dt,126)
    ) A,
     (
    SELECT distinct CONVERT(char(10), Dt,126) as '统计时间'
      ,[MaxOnline] as '最高在线'
      ,[AvgOnline] as '平均在线'
      FROM [Datagram].[dbo].[DayOnlineCount] with(nolock)
    where CONVERT(char(10), Dt,126) between '2013-05-01' and '2013-05-04')
    B,
    (
    select distinct CONVERT(char(10), F_TIME,126) as '统计时间',
    F_BACKNUM as '返回人数' from REPORT.DBO.USERNUM
    where CONVERT(char(10), F_TIME,126) between '2013-05-01' and '2013-05-04'
    ) C where A.统计时间=B.统计时间 and A.统计时间=C.统计时间
      

  2.   


    create proc promuha
    as
    begin
     set nocount on;
     
     with a as
     (SELECT distinct CONVERT(char(10), Dt,126) as '统计时间',sum([F_REGCOUNT]) as '注册量'
            FROM [Datagram].[dbo].[RegisterCount] with(nolock)
      where CONVERT(char(10), Dt,126) between '2013-05-01' and '2013-05-04'
      group by CONVERT(char(10), Dt,126)),
      b as
      (SELECT distinct CONVERT(char(10), Dt,126) as '统计时间'
          ,[MaxOnline] as '最高在线'
          ,[AvgOnline] as '平均在线'
       FROM [Datagram].[dbo].[DayOnlineCount] with(nolock)
       where CONVERT(char(10), Dt,126) between '2013-05-01' and '2013-05-04'),
      c as
      (select distinct CONVERT(char(10), F_TIME,126) as '统计时间',
       F_BACKNUM as '返回人数' from REPORT.DBO.USERNUM
       where CONVERT(char(10), F_TIME,126) between '2013-05-01' and '2013-05-04')
      select a.统计时间,a.注册量,b.最高在线,b.平均在线,c.返回人数
       from a
       left join b on a.统计时间=b.统计时间
       left join c on a.统计时间=c.统计时间
       order by a.统计时间
    end