1
I have the following sql statement:
Select
Notas.NotaID,
Materias.MateriaNome,
Alunos.AlunoNome,
Alunos.AlunoID,
max(case when NotaBimestre = 1 then Nota else null end) as 1bim,
max(case when NotaBimestre = 2 then Nota else null end) as 2bim,
max(case when NotaBimestre = 3 then Nota else null end) as 3bim,
max(case when NotaBimestre = 4 then Nota else null end) as 4bim
From ((notas
INNER JOIN Materias
ON Notas.MateriaID = Materias.MateriaID)
INNER JOIN Alunos
ON Notas.AlunoID = Alunos.AlunoID)
group by (NotaID)
Upshot:
How do I stay in that pattern:
ID | ALUNO | DISCIPLINA | 1BIM| 2BIM | 3BIM | 4BIM
16 | NATANAEL | BANCO DE DADOS | 8 | | |
17 | GUSTAVO | PROGRAMAÇÃO PARA WEB | 9.5 | 8 | 8.5 | 10
Which DBMS you are using?
– Sorack
You will need to consult the grade table 1 time for each quarter, not go through it just once as it is in your query. I recommend using Subqueries for such
– Jefferson Quesado
Take the "note id" from GROUP BY.
– Motta
@Motta will not help because he needs to check the two months. In case he will have to make a table with the values and then perform a
PIVOT
– Sorack