0
我使用SQL Server 2000,從而無法使用CTE的連接三個SQL查詢
DECLARE @reportdate AS DATETIME
SET @reportdate='08/26/2013'
1查詢
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
3ND查詢
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
查找到UNION ALL它可以讓你對所有三個查詢加入到一個表 –