Is it faster to have multiple MySQL Count
instances in one query or separate queries for each count instance? And If so how would I combine these two queries?
$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'";
Your table is the same. Most of the conditions in the WHERE
clause are the same. So, you should be able to use conditional aggregation:
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'". ";
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.