mysql query - peak concurrent calls CDR data

后端 未结 3 750
执笔经年
执笔经年 2021-01-14 05:50

Hi I need help working out how to calculate how many peak concurrent calls I have in a day from my CDR date stored in MySQL.

The data set looks like this:

         


        
3条回答
  •  逝去的感伤
    2021-01-14 06:05

    Try adding +1 for each start of call, and -1 for each end, then just get cumulative sum of that +1/-1 column
    ***Convert the calldate if needed or use your format:

    set @from:='2015-02-01';
    set @to:='2015-03-01';
    set @csum:=0;
    SELECT DT,CallCount, (@csum := @csum + CallCount) as cumulative_sum
    FROM 
    (select calldate AS DT, 1 AS CallCount
     from cdr
     where calldate between @from and @to
    
     union all
    
     select ADDDATE(calldate,INTERVAL duration SECOND) AS DT, -1 AS CallCount
     from cdr 
     where calldate between @from and @to
      ) Calls
    ORDER BY 1 asc;
    

提交回复
热议问题