2
I have a table of evaluations in the format
TABLE AVALIACAO
(id_avaliacao, id_pessoa, concluida, segunda_avaliacao)
and another table that records the notes
TABLE NOTA
(id_nota, id_avaliacao, id_questao, nota)
Quite abstractly, what happens is that a person can have a second assessment if they ask for it. In this case, the value of the second evaluation_evaluation field would be char 'S'
.
My question: how do I make an sql that picks up the sum of NOTE.note, grouping by person (by id_pessoa
) and that, if it is a second evaluation, take the sum only of the second evaluation, instead of the two.
For example.
AVALIAÇÂO
id_avaliacao id_pessoa concluida segunda_avaliacao
1 1 'S' 'N'
2 1 'S' 'S'
NOTE TABLE NOTE
id_nota id_avaliacao id_questao nota
1 1 1 1
2 1 2 1
3 1 3 1
4 2 1 2
5 2 2 2
6 2 3 2
As person 1 had a second evaluation, the sum of her grades should be 6 (not 9).
Passing by again, I was curious to know if my query solved your problem, so I decided to test it. It actually solves as I first thought. Here is the test: http://sqlfiddle.com/#! 3/276805/1/0. Has your problem been solved? Let the people who tried to help you know.
– Caffé