I have the following table, which has the records of the answers to some academic quizzes:
Respostas
-SEMESTRE_ID (foreign key for semester of the quiz)
-PERGUNTA_ID (foreign key for the question of the quiz)
-DISCIPLINA_ID (foreign key for the subject being evaluated)
-DOCENTE_ID (foreign key for the teacher being evaluated)
-QUIZ_ID (each person answering a quiz has an unique quiz_id)
-TIPOAULA (type of class, doesn't matter for this context)
-DATA (date, doesn't matter for this context)
-ID (unique id of an answer)
-RESPOSTA (value of the answer, from 1 to 5)
So, a quizz of a given semester has multiples questions of different subjects, which can be evaluated by people (don't need to necessarily vote on all the questions).
The query I want to achieve is:
What's the id and acronym of the subjects that had at least a 5 in each one of the questions of the quiz of semester of id 21?
I've solved it using the counting strategy:
SELECT DISCIPLINA.DISCIPLINA_ID, SIGLA
FROM RESPOSTAS, DISCIPLINA
WHERE RESPOSTAS.DISCIPLINA_ID = DISCIPLINA.DISCIPLINA_ID AND SEMESTRE_ID = 21 AND RESPOSTA = 5
GROUP BY DISCIPLINA.DISCIPLINA_ID, SIGLA
HAVING COUNT(DISTINCT PERGUNTA_ID) = (SELECT COUNT(DISTINCT PERGUNTA_ID) FROM RESPOSTAS WHERE SEMESTRE_ID = 21);
But this is for an assignment and we're asked to also solve it by using the double negation strategy, which I can't seem to understand how to achieve the expected result.