I have a query that returns me the student grades in certain tests. The amount of test can vary. I use the Pivot command to transform the test names into columns and thus organize test / note, as shown in the following image:
Where"SENEM_01", "02", "03" are test names. What I need is to average these values. Remembering that the amount of test can vary.
My query looks like this:
WITH notas_testes as(
SELECT
ft.inscricao,
ft.nota_num,
ft.idteste,
a.nome,
ft.unidade
from [Easy395].[dbo].[aluno] a
INNER JOIN [Easy395].[dbo].[faz_teste] ft
ON a.inscricao = ft.inscricao
)
select *
from notas_testes
PIVOT (SUM(nota_num) FOR idteste IN ([SENEM_01], [SENEM_02], [SENEM_03]))pvt