我使用的是 sql server 2000,所以不能使用 CTE
DECLARE @reportdate AS DATETIME
SET @reportdate='08/26/2013'
第一次查询
SELECT SUM(NENTEREDACD) AS calls,
DINTERVALSTART
FROM dbo.QUEUESTATS
WHERE ( DINTERVALSTART > @reportdate + ' 00:00:00.000' )
AND ( DINTERVALSTART < DATEADD(d, 1, @reportdate) + ' 00:00:00.000' )
GROUP BY DINTERVALSTART
ORDER BY DINTERVALSTART
第二次查询
SELECT count(cname) AS AvaiAgents,
dintervalstart AS startdatetime
FROM (SELECT dintervalstart,
cname
FROM [dbo].[AGENTSTATS]
GROUP BY dintervalstart,
cname
HAVING ( DINTERVALSTART > @reportdate + ' 00:00:00.000' )
AND ( DINTERVALSTART < DATEADD(d, 1, @reportdate) + ' 00:00:00.000' )) T
GROUP BY T.dintervalstart
第三次查询
SELECT count(cname) AS ActiveAgents,
dintervalstart AS startdatetime
FROM (SELECT dintervalstart,
cname
FROM [dbo].[AGENTSTATS1]
GROUP BY dintervalstart,
cname
HAVING ( DINTERVALSTART > @reportdate + ' 00:00:00.000' )
AND ( DINTERVALSTART < DATEADD(d, 1, @reportdate) + ' 00:00:00.000' )) T
GROUP BY T.dintervalstart
我只想从第一个查询中提取记录,所以它应该是这样的,所以我需要从三个不同的查询中获取三列。常见的是时间戳
I inetval Calls Avaiagents Active agents
08/26/2012 20 22 23