06/11/2010, 10:35
|
| | Fecha de Ingreso: agosto-2009 Ubicación: Lima
Mensajes: 226
Antigüedad: 15 años, 3 meses Puntos: 3 | |
Respuesta: mostrar ultimo valor de cada columna hola flaviovich, hice lo que me indicaste y no sale ni un registro, pero si pruebo hasta el t2 si sale un registro
SELECT T0.ano,T0.meta,T0.mes, m1,T0.m2, T0.m3, T0.m4, T0.m5 FROM #rm T0
inner JOIN (
SELECT ano,meta,mes,max(x) x FROM #rm T1 WHERE m1 >= 0 GROUP BY ano,meta,mes
) T1 ON T0.ano = T1.ano AND T0.meta = T1.meta AND T0.mes = T1.mes AND T0.x = T1.x
inner JOIN (
SELECT ano,meta,mes,max(x) x FROM #rm T2 WHERE m2 >= 0 GROUP BY ano,meta,mes
) T2 ON T0.ano = T2.ano AND T0.meta = T2.meta AND T0.mes = T2.mes AND T0.x = T2.x
inner JOIN (
SELECT ano,meta,mes,max(x) x FROM #rm T3 WHERE m3 >= 0 GROUP BY ano,meta,mes
) T3 ON T0.ano = T3.ano AND T0.meta = T3.meta AND T0.mes = T3.mes AND T0.x = T3.x
INNER JOIN (
SELECT ano,meta,mes, max(x) x FROM #rm T4 WHERE m4 >= 0 GROUP BY ano,meta,mes
) T4 ON T0.ano = T4.ano AND T0.meta = T4.meta AND T0.mes = T4.mes AND T0.x = T4.x
INNER JOIN (
SELECT ano,meta,mes, max(x) x FROM #rm T5 WHERE m5 >= 0 GROUP BY ano,meta,mes
) T5 ON T0.ano = T5.ano AND T0.meta = T5.meta AND T0.mes = T5.mes AND T0.x = T5.x |