2013-08-12 39 views

回答

1

您需要將qv.question_view_id IS NULL子句作爲JOIN的一部分,而不是WHERE

SELECT qt.user_id, count(q.question_id) cnt 
    FROM questions q 
    INNER JOIN questions_to qt ON qt.question_id = q.question_id 
    LEFT JOIN question_view qv ON q.question_id = qv.question_id 
    -- Not that I've moved this clause into the JOIN condition. 
    AND qv.question_view_id IS NULL 
WHERE qt.user_id = 13 
GROUP BY qt.user_id