0

我使用的是 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 
4

1 回答 1

0

cte 只是带有 using 关键字的派生表。你能用老式的方法吗?

select somefields
from a_table join
(select etc) temp on t.something = a_table.something
于 2013-08-28T19:30:36.437 回答