Ver Mensaje Individual
  #1 (permalink)  
Antiguo 14/04/2015, 11:32
magalvezv
 
Fecha de Ingreso: abril-2015
Mensajes: 2
Antigüedad: 9 años, 1 mes
Puntos: 0
Información Consulta agrupacion de datos por fila

Hola estimados, soy Nuevo en este foro, la verdad es que no encuentro la respuesta y si alguien me puee ayudar, mejor.

Mi query es:

Código SQL:
Ver original
  1. SELECT
  2.       rt.[name] AS [DESC]
  3.      ,CASE WHEN [crew] = 'Grupo 1' THEN ROUND(SUM(stat.[duration] / 3600),2)END AS Grupo1
  4.      ,CASE WHEN [crew] = 'Grupo 2' THEN ROUND(SUM(stat.[duration] / 3600),2)END AS Grupo2
  5.      ,CASE WHEN [crew] = 'Grupo 3' THEN ROUND(SUM(stat.[duration] / 3600),2)END AS Grupo3
  6.      ,CASE WHEN [crew] = 'Grupo 4' THEN ROUND(SUM(stat.[duration] / 3600),2)END AS Grupo4
  7.   FROM [scmapview].[dbo].[hist_statusevents] stat
  8.     INNER JOIN [scmapview].[dbo].[hist_exproot] eroot
  9.       ON stat.shiftindex = eroot.shiftindex
  10.    INNER JOIN scmapview.dbo.hist_reasontable AS rt
  11.       ON stat.shiftindex = rt.shiftindex
  12.       AND stat.[STATUS] = rt.[STATUS]
  13.       AND stat.[category] = rt.[category]
  14.       AND stat.[reason] = rt.[reason]
  15.   WHERE [shiftdate] BETWEEN '2015-01-01' AND '2015-01-07'
  16.   AND stat.[STATUS] IN (4) AND [unit] = '1'
  17.   GROUP BY crew , rt.[name]
  18.   ORDER BY rt.[name]

y me entrega esto:

Desc Grupo 1 Grupo2 grupo3 grupo 4
ABASTECIMIENTO COMBUSTIBLE NULL NULL NULL 48.93
ABASTECIMIENTO COMBUSTIBLE NULL 9.21 NULL NULL
ABASTECIMIENTO COMBUSTIBLE NULL NULL 54.35 NULL
ABASTECIMIENTO COMBUSTIBLE 27.36 NULL NULL NULL
CAMBIO DE BANCO 0 NULL NULL NULL

Quiero hacer una query que agrupe asi:

Desc Grupo 1 Grupo2 grupo3 grupo 4
ABASTECIMIENTO COMBUSTIBLE 27.36 NULL 54.35 48.93

Alguien sabe como hacerlo?
gracias.

Última edición por gnzsoloyo; 14/04/2015 a las 11:41