我遇到了一个问题,我已经坚持了一段时间。
我有一个判断表(exp_judging),它使用不同的judge_id来保存相同rel_id的多行。通常情况下,至少有3行具有相同的rel_id。
我需要返回entry_id,其中'stage_1'列中至少有2行'1',每行具有相同的rel_id,stage_2为IS NULL,member_group等于5.
以下查询是我觉得我有的壁橱,但我想它还有一英里的距离。
SELECT sub.entry_id
FROM exp_judging AS jud
LEFT JOIN exp_submissions AS sub ON jud.rel_id = sub.id
WHERE jud.stage_2 IS NULL
AND (jud.stage_1=1) >= 2
AND sub.member_group = 5
GROUP BY jud.rel_id
LIMIT 1
如果有人能说明如何实现这一目标,我将非常感激。
谢谢。
SQL FIDDLE:http://sqlfiddle.com/#!2/6d7e2/1
答案 0 :(得分:0)
SELECT sub.entry_id
FROM exp_judging AS jud
LEFT JOIN exp_submissions AS sub ON jud.rel_id = sub.id
WHERE jud.stage_2 IS NULL
AND jud.stage_1 = 1
AND sub.member_group = 5
GROUP BY jud.rel_id
HAVING COUNT(*) >= 2