2011-01-31 7 views

答えて

4

これは動作します、:SQLLiteで

SELECT count(Answers.ID) as answertotal, Questions.* 
FROM Questions 
LEFT JOIN Answers ON Answers.qid=Questions.ID 
GROUP BY Questions.ID 
ORDER BY answertotal 

を、あなたはこのような追加の層を追加する必要があります。

SELECT q.*, tots.answertotal 
FROM Questions q 
INNER JOIN ( 
    SELECT count(Answers.ID) as answertotal, Questions.ID as questionid 
    FROM Questions 
    LEFT JOIN Answers ON Answers.qid=Questions.ID 
    GROUP BY Questions.ID 
) tots ON tots.questionid = q.ID 
ORDER BY tots.answertotal 
関連する問題