加速COUNT查询

时间:2014-04-25 07:46:39

标签: mysql sql

我有以下查询,我正在循环选择类别。 任何人都可以看到加快此查询速度的方法,因为它目前花费太长时间才能返回结果。

SELECT COUNT(entry_id) AS count_result
FROM (
    SELECT sub.entry_id
    FROM exp_judging AS jud1
    JOIN exp_judging AS jud2 ON jud1.rel_id = jud2.rel_id AND jud2.judge_id = 779 AND jud2.stage_2 IS NULL
    JOIN exp_submissions AS sub ON jud2.rel_id = sub.id 
    WHERE jud1.stage_1 = 1 
    AND sub.member_group = 5
    AND sub.category_id = 10
    GROUP BY jud1.rel_id
    HAVING COUNT(sub.entry_id) >= 3
) AS a

1 个答案:

答案 0 :(得分:0)

我不明白为什么你需要那里的nestes SELECT语句。它看起来像而不是

SELECT COUNT(entry_id) AS count_result
FROM (
    SELECT sub.entry_id
    ...
) AS a

你可以简单地做

SELECT COUNT(sub.entry_id) AS count_result
...

这可能有助于DBMS优化您的请求。