日期:2014-05-17  浏览次数:20664 次

多表查询,存储过程编写(在线等)


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'




根据日期范围查询, 编写一个存储过程,
返回结果为 
"统计时间" '注册量' '最高在线' '平均在线' '返回人数'


求高手赐教~

------解决方案--------------------

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.统计时间

------解决方案--------------------

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