Como hacerlo ? Pivot ?

26/05/2009 - 02:04 por Penta | Informe spam
Estimados.
Utilizo SS2000
Tengo una tabla con asistencia.

Id, Fecha

Y lo agrupare por semanas

Algo asi:
Select id, datepart(week,fecha) Semana,count(*) Presente From TABLA
group by if,datepart(week,fecha)

Resultado:
id Semana Presente
1 14 5
1 16 2
2 14 7

Quisiera:

Id 14 15 16

1 5 0 2
2 7 0 0

Me suena a Pivot? ya se me complicó :(

PENTA.
 

Leer las respuestas

#1 Alejandro Mesa
26/05/2009 - 02:37 | Informe spam
Penta,

Si el # de las semanas es sabido de antemano, entonces puedes usar:

select
id,
max(case when Semana = 14 then Pesente end) as sem_14,
max(case when Semana = 15 then Pesente end) as sem_15,
max(case when Semana = 16 then Pesente end) as sem_16
from
(
Select
id,
datepart(week,fecha) as Semana,
count(*) as Presente
From
TABLA
group by
id , datepart(week,fecha)
) as t
group by id;
GO


AMB


"Penta" wrote:

Estimados.
Utilizo SS2000
Tengo una tabla con asistencia.

Id, Fecha

Y lo agrupare por semanas

Algo asi:
Select id, datepart(week,fecha) Semana,count(*) Presente From TABLA
group by if,datepart(week,fecha)

Resultado:
id Semana Presente
1 14 5
1 16 2
2 14 7

Quisiera:

Id 14 15 16

1 5 0 2
2 7 0 0

Me suena a Pivot? ya se me complicó :(

PENTA.







Preguntas similares