我在子查询和一些分组方面遇到问题。子查询是从整个表中选择,而不仅仅是单个组...我的代码
SELECT SEC_TO_TIME(TIME_TO_SEC(call_start) - TIME_TO_SEC(call_start)%(30*60)) AS intervals,
COUNT(*) AS OFFERED,
SUM(agent_duration) AS AGENT_SUM,
SUM(TIME_TO_SEC(TIMEDIFF(dequeue_time, enqueue_time))) AS ANS_TIME_SUM,
COUNT(DISTINCT agent_username) AS UNIQUE_AGENTS,
(SELECT COUNT(*) FROM call_detail
WHERE TIME_TO_SEC(TIMEDIFF(dequeue_time, enqueue_time)) < 40) AS SLA,
SUM(queue_duration) AS TOTAL_QUEUE_TIME
FROM call_detail
WHERE DATE(call_start) = CURDATE()
GROUP BY intervals
我的目标是让该子查询仅返回该特定时间间隔内 TIMEDIFF 结果小于 40 的记录数
谢谢。