Ver Mensaje Individual
  #4 (permalink)  
Antiguo 18/01/2013, 09:56
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: Select con Group By parcial

Código SQL:
Ver original
  1. CREATE TABLE #temp
  2. (
  3. id INT,
  4. producto VARCHAR(20),
  5. debe INT,
  6. haber INT
  7. )      
  8.  
  9. INSERT INTO #temp VALUES (191, 'Listados',  NULL ,NULL)
  10. INSERT INTO #temp VALUES (192, 'Productos',      100,  NULL)
  11. INSERT INTO #temp VALUES (192, 'Productos',      NULL, 100)
  12. INSERT INTO #temp VALUES (192, 'Productos',      NULL, 120)
  13. INSERT INTO #temp VALUES (193, 'Servicios',      NULL, NULL)       
  14.  
  15. SELECT id, producto,SUM(debe) AS debe,SUM(haber) AS haber FROM #temp GROUP BY id,producto

saludos!
__________________
What does an execution plan say to t-sql query? Go f**k yourself, if you are not happy with me