以下查询给出exp_judging表中有多少行的计数,字段pre中的值为1,其中exp_submissions中也有一个匹配列,member_group为5
SELECT COUNT(*) AS count_result
FROM exp_judging AS jud
LEFT JOIN exp_submissions AS sub ON jud.rel_id = sub.id
WHERE jud.pre = 1
AND sub.member_group = 5
这非常有效.但是,将来在’exp_judging’表中会有多行具有相同的’rel_id’.
如何确保每行中只有一行被计算在内?
我尝试将GROUP BY添加到最后,但它只显示1个结果,而不是之前的4个结果. (还没有重复)
GROUP BY jud.rel_id
编辑:
尝试了以下,但仍然只是显示1:
SELECT COUNT(DISTINCT jud.rel_id) AS count_result
FROM exp_judging AS jud
LEFT JOIN exp_submissions AS sub ON jud.rel_id = sub.id
WHERE jud.pre = 1
AND sub.member_group = $member_group
GROUP BY jud.rel_id