basandonos en el ejemplo anterior:
Código SQL:
Ver originalSELECT * FROM(
SELECT num, MIN(START) AS [START], MAX([END]) AS [END], state, SUM(duration) AS duration FROM #temp WHERE state=2 GROUP BY num,state
UNION
SELECT num, START, [END],state, duration FROM #temp WHERE state=20
) AS completa ORDER BY campo1,campo2 ASC/DESC