gpt4 book ai didi

php - 多个 Count 的 MySQL 性能

转载 作者:行者123 更新时间:2023-11-29 07:33:28 24 4
gpt4 key购买 nike

在一个查询中使用多个 MySQL Count 实例更快,还是每个计数实例单独查询更快?如果是这样,我将如何组合这两个查询?

 $msd_call_qry = "SELECT count(event) AS MissedCalls  FROM queuelogdb.queue_log WHERE (agent = '$agent_name[0]' OR agent = '$agent_name[1]')"
. " AND (event = 'ABANDON' OR event = 'RINGNOANSWER') AND queuename IN ('500','505') AND time BETWEEN '$lastDay' AND '$today'";

$ttl_call_qry = "SELECT count(event) AS TotalCalls from queuelogdb.queue_log WHERE (agent = '$agent_name[0]' OR agent = '$agent_name[1]') "
. "AND event = 'CONNECT' AND queuename IN ('500','505') AND time BETWEEN '$lastDay' AND '$today'";

最佳答案

你的 table 是一样的。 WHERE 子句中的大多数条件都是相同的。因此,您应该能够使用条件聚合:

SELECT SUM(event = 'ABANDON' OR event = 'RINGNOANSWER') AS MissedCalls,
SUM(event = 'CONNECT') AS TotalCalls
FROM queuelogdb.queue_log
WHERE agent IN ('$agent_name[0]', '$agent_name[1]') AND
queuename IN ('500', '505') AND
time BETWEEN '$lastDay' AND '$today'". ";

关于php - 多个 Count 的 MySQL 性能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31785073/

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