다음과 유사한 데이터베이스 테이블이 있습니다.
답변 표
quiz_id question_id answer_id user_answer_id
--------------------------------------------------
2 12 23 23
--------------------------------------------------
2 12 34 34
--------------------------------------------------
2 13 35 36
--------------------------------------------------
2 13 33 33
--------------------------------------------------
2 14 28 28
--------------------------------------------------
user_quizzes
quiz_id assignment_id user_id ....
--------------------------------------------------
2 3 12
--------------------------------------------------
내 쿼리가 answer_id = user_answer_id 결과가되어야하는 사람들의 question_id 수를 제공하고 싶습니다.-total 2
하위 쿼리와 having
절을 사용합니다 .
select count(*)
from (select a.quiz_id
from answers a
group by a.quiz_id
having sum(answer_id <> user_answer_id) = 0
) q;
또는 정답 만있는 퀴즈는 몇 개입니까? 이로 인해 다음이 발생할 수 있습니다.
select count(*)
from quizzes q
where not exists (select 1
from answers a
where a.quiz_id = q.quiz_id and
a.answer_id <> a.user_answer_id
);
이것은라는 테이블을 가정합니다 quizzes
. . . 또한 각 퀴즈에 답이 하나 이상 있다고 가정합니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다