简体   繁体   English

具有多个计数的MySQL性能

[英]MySQL performance with multiple Counts

Is it faster to have multiple MySQL Count instances in one query or separate queries for each count instance? 在一个查询中有多个MySQL Count实例或为每个count实例单独查询是否更快? 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. WHERE子句中的大多数条件是相同的。 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'". ";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM