并发通话结果的返回时间表

时间:2018-09-13 12:27:18

标签: sql

通过该站点的大力帮助,我提出了以下SQL查询,以在输入的时间范围内返回电话系统中的最高并发呼叫。我正在通过Microsoft SQL Server Management Studio访问SQL Server 2012。我现在要查找的是,还返回此高峰并发发生的时间范围(开始和结束)。

以下是查询:

With C1 AS (
  SELECT initiateddatetimeutc AS ts, +1 AS TYPE,
         ROW_NUMBER() OVER(ORDER BY initiateddatetimeutc) AS start_ordinal
   FROM interactionsummary
   WHERE initiateddatetimeutc >= '11/24/2017 11:00:00' 
     and initiateddatetimeutc <= '11/24/2017 17:00:00'
   UNION ALL
   SELECT terminateddatetimeutc, -1, NULL
   FROM interactionsummary
   WHERE initiateddatetimeutc >= '11/24/2017 11:00:00' 
     and initiateddatetimeutc <= '11/24/2017 17:00:00'
), C2 AS (
   SELECT *,ROW_NUMBER() OVER(ORDER BY ts, TYPE) AS start_or_end_ordinal
   FROM C1
)
SELECT MAX(2 * start_ordinal - start_or_end_ordinal) AS MaxConcurrent
FROM C2
WHERE TYPE = 1

0 个答案:

没有答案