Ver Mensaje Individual
  #6 (permalink)  
Antiguo 03/03/2015, 08:55
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, 8 meses
Puntos: 774
Respuesta: Demasiado pedir para SQL?

basandonos en el ejemplo anterior:

Código SQL:
Ver original
  1. SELECT * FROM(
  2. SELECT num, MIN(START) AS [START], MAX([END]) AS [END], state, SUM(duration) AS duration FROM #temp WHERE state=2 GROUP BY num,state
  3. UNION
  4. SELECT num, START, [END],state, duration FROM #temp WHERE state=20
  5. ) AS completa ORDER BY campo1,campo2 ASC/DESC
__________________
What does an execution plan say to t-sql query? Go f**k yourself, if you are not happy with me