Usa la forma tradicional de pivotear filas a columnas que es:
- Agrupar (group by)
- regar valores (expresion CASE)
- Agregar (MIN/MAX/SUM/etc.)
select
Num_Estudiante, Codigo_Clase,
max(case when Termino_Clase = '1510' then Nota end) as Nota_1,
max(case when Termino_Clase = '1520' then Nota end) as Nota_2,
max(case when Termino_Clase = '1530' then Nota end) as Nota_3
from
tuTabla
group by
Num_Estudiante, Codigo_Clase;
Si no quieres depender del codigo de los terminos, entonces enumera primero y usa el valor calculado.
with R as (
select *, row_number() over(partition by Num_Estudiante, Codigo_Clase order by Termino) as rn
from tuTabla
)
select
Num_Estudiante, Codigo_Clase,
max(case when rn = 1 then Nota end) as Nota_1,
max(case when rn = 2 then Nota end) as Nota_2,
max(case when rn = 3 then Nota end) as Nota_3
from
R
group by
Num_Estudiante, Codigo_Clase;
Si tienes mas de tres terminos posibles y deseas que el query sea dinamico entonces ya sabes, tendras que recurrir a pivoteo dinamico. Busca en este mismo foro por "pivot dinamico" y encontraras varias sugerencias.
AMB
Some guidelines for posting questions...
AYÚDANOS A AYUDARTE, guía básica de consejos para formular preguntas