Ver Mensaje Individual
  #2 (permalink)  
Antiguo 14/04/2015, 11:45
Avatar de Libras
Libras
Colaborador
 
Fecha de Ingreso: agosto-2006
Ubicación: En la hermosa perla de occidente
Mensajes: 7.412
Antigüedad: 17 años, 9 meses
Puntos: 774
Respuesta: Consulta agrupacion de datos por fila

simple ;)


Código SQL:
Ver original
  1. SELECT DESC,SUM(grupo1), SUM(grupo2), SUM(grupo3), SUM(grupo4) FROM
  2. (
  3. SELECT
  4.       rt.[name] AS [DESC]
  5.      ,CASE WHEN [crew] = 'Grupo 1' THEN ROUND(SUM(stat.[duration] / 3600),2)END AS Grupo1
  6.      ,CASE WHEN [crew] = 'Grupo 2' THEN ROUND(SUM(stat.[duration] / 3600),2)END AS Grupo2
  7.      ,CASE WHEN [crew] = 'Grupo 3' THEN ROUND(SUM(stat.[duration] / 3600),2)END AS Grupo3
  8.      ,CASE WHEN [crew] = 'Grupo 4' THEN ROUND(SUM(stat.[duration] / 3600),2)END AS Grupo4
  9.   FROM [scmapview].[dbo].[hist_statusevents] stat
  10.     INNER JOIN [scmapview].[dbo].[hist_exproot] eroot
  11.       ON stat.shiftindex = eroot.shiftindex
  12.    INNER JOIN scmapview.dbo.hist_reasontable AS rt
  13.       ON stat.shiftindex = rt.shiftindex
  14.       AND stat.[STATUS] = rt.[STATUS]
  15.       AND stat.[category] = rt.[category]
  16.       AND stat.[reason] = rt.[reason]
  17.   WHERE [shiftdate] BETWEEN '2015-01-01' AND '2015-01-07'
  18.   AND stat.[STATUS] IN (4) AND [unit] = '1'
  19.   GROUP BY crew , rt.[name]
  20. --  ORDER BY rt.[name]
  21. ) AS t1
  22. GROUP BY DESC
__________________
What does an execution plan say to t-sql query? Go f**k yourself, if you are not happy with me