0
SELECT `listener` ,
SEC_TO_TIME( SUM( TIME_TO_SEC( `call_time` ) ) ) AS total_time,
COUNT( `listener` ) AS number
FROM calls
WHERE listened_date = '2013-05-09'
AND type in ('column1','column2')
AND id
IN ( SELECT id
FROM calls
GROUP BY CONCAT( name, ' ', when ) )
GROUP BY `listener`

此查询运行缓慢,并且使其他查询无法同时运行。我怎样才能使这个更轻?

我认为 IN 让它变慢。在这种情况下有什么替代方案?

4

1 回答 1

2

也许 ?:

SELECT c.`listener` ,
       SEC_TO_TIME(SUM(TIME_TO_SEC(c.`call_time`))) AS total_time,
       COUNT(c.`listener`) AS number
FROM calls c
WHERE c.listened_date = '2013-05-09'
  AND c.TYPE IN ('column1',
                 'column2')
  AND EXISTS (SELECT 0
              FROM calls c2
              WHERE c2.id = c.id)
GROUP BY c.`listener`
于 2013-05-09T07:55:11.403 回答