gpt4 book ai didi

mysql - 无法在mysql中进行求和和除法

转载 作者:行者123 更新时间:2023-11-29 00:36:58 25 4
gpt4 key购买 nike

这是我的mysql查询

    SELECT IntervalStartTime,IFNULL(SUM(AbandonedCalls),0) AS AbandonedCallSum,SUM(QueueTime) AS QTS,SUM(RingTime) AS RTS,
IFNULL(SUM(AnsweredCalls),0) AS AnsweredCallSum
FROM intervalqueuestatistics
WHERE CallCenterId=17 AND DATE_FORMAT(IntervalStartTime,'%m')=10 AND DATE_FORMAT(IntervalStartTime,'%Y')=2012
GROUP BY DATE_FORMAT(IntervalStartTime,'%d');

现在我想计算一个值(SUM(QueueTime)+SUM(RingTime))/SUM(AnsweredCalls)

所以我相应地修改了我的查询如下

    SELECT IntervalStartTime,IFNULL(SUM(AbandonedCalls),0) AS AbandonedCallSum,SUM(QueueTime) AS QTS,SUM(RingTime) AS RTS,
IFNULL(SUM(AnsweredCalls),0) AS AnsweredCallSum,IFNULL(SUM(QueueTime),0) + IFNULL(SUM(RingTime),0)/IFNULL(SUM(AnsweredCalls),0)
FROM intervalqueuestatistics
WHERE CallCenterId=17 AND DATE_FORMAT(IntervalStartTime,'%m')=10 AND DATE_FORMAT(IntervalStartTime,'%Y')=2012
GROUP BY DATE_FORMAT(IntervalStartTime,'%d');

但是在执行时它并没有给我正确的答案。

例如这个查询返回的行之一

 QTS    RTS   AnsweredCallSum CalculatedField 
188000 41645 9 192627.222

但是CalculatedField是错误的,按照上面的计算应该是25516.11

最佳答案

如果 SUM(AnsweredCalls) 为 0,则除以 0,它不应该起作用。

关于mysql - 无法在mysql中进行求和和除法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13802835/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com