0

回答されていない質問に基づいて、合計数と新しい数を取得しようとしています。

次のような 2 つの SQL 呼び出しがあります。

// retrieves all ids of questions and the timestamps when recorded
SELECT id, timestamp FROM `profile_questions` q WHERE q.user_id=5

// output:
id timestamp
-- ---------
1  1374677344
2  1374677514

// retrieves all answered questions
SELECT a.timestamp 
FROM `profile_answers` a 
LEFT JOIN profile_questions q ON q.id = a.question_id 
WHERE a.answered_by=5

2 つのステートメントを組み合わせて、合計質問数と新しい質問数を返す方法はありますか? 基本的に、回答されていない質問の数ですか?

4

1 に答える 1

2

To count all questions not answered by a user do

SELECT count(q.id)
FROM `profile_questions` q 
LEFT JOIN profile_answers a ON q.id = a.question_id 
                            and q.user_id = a.answered_by
WHERE q.user_id = 5
and a.answered_by IS NULL
于 2013-07-24T19:20:11.417 に答える