1
I have a teacher evaluation table and another with student evaluations:
tbl_teacher
id | nome
----------------------------
1 | José
2 | Maria
3 | Paulo
tbl_evaluation
id | idprofessor | avaliacao | data
-------------------------------------
1 | 3 | R | 2015-01-01
2 | 2 | B | 2015-01-01
3 | 3 | B | 2015-01-01
The student evaluation may be R-Bad, B-Good, but how could you create a listing like the one below using OVER, as it does not allow you to put a WHERE for this type of filtering?
avaliacoes_ruins | avaliacoes_boas
----------------------------------
1 | 2
Or
professor |avaliacoes_ruins |avaliacoes_boas
---------------------------------------------
José |0 |0
Maria |0 |1
Paulo |1 |1
I know that the last case would be possible to do SQL
SELECT
nome,
(SELECT (COUNT) FROM tbl_avaliacao WHERE idprofessor = tbl_professor.id AND avaliacao = 'R') AS avaliacoes_ruins,
(SELECT (COUNT) FROM tbl_avaliacao WHERE idprofessor = tbl_professor.id AND avaliacao = 'B') AS avaliacoes_boas
FROM
tbl_professor
But in the above case the cost of SQL will be high.