Simultaneous calls

后端 未结 2 554
-上瘾入骨i
-上瘾入骨i 2021-01-18 05:07

I\'m trying to calculate the number of simultaneous calls at the time a particular call is made by looking at the datetime ranges. My query works, but takes ~10 minutes to p

2条回答
  •  广开言路
    2021-01-18 05:31

    Use SQL like this to get a list of start/end events...

    Select CallStart, 1 As CallCount From #rg
    Union All
    Select CallEnd, -1 From #rg
    Order By CallStart
    

    ...then treat this as a simple running totals problem, which is solved differently depending upon your SQL Server version or can be easily addressed in code if that's an option.

提交回复
热议问题