Ver Mensaje Individual
  #2 (permalink)  
Antiguo 07/02/2012, 14:04
Avatar de Libras
Libras
Colaborador
 
Fecha de Ingreso: agosto-2006
Ubicación: En la hermosa perla de occidente
Mensajes: 7.412
Antigüedad: 18 años, 5 meses
Puntos: 774
Respuesta: no puedo crear la consulta sql

Medio raro el query pero obtiene lo que necesitas :)
Código SQL:
Ver original
  1. CREATE TABLE #temp
  2. (
  3. rut INT,
  4. noc VARCHAR(3)
  5. )
  6.  
  7. CREATE TABLE #temp2
  8. (
  9. rut INT,
  10. nlic VARCHAR(3)
  11. )
  12.  
  13. INSERT INTO #temp VALUES (15,'01')
  14. INSERT INTO #temp VALUES (15,'02')
  15. INSERT INTO #temp VALUES (16,'03')
  16.  
  17. INSERT INTO #temp2 VALUES (15,'L3')
  18. INSERT INTO #temp2 VALUES (15,'L2')
  19. INSERT INTO #temp2 VALUES (17,'L3')
  20.  
  21. SELECT rut,SUM(oc) AS oc, SUM(nlic) AS nlic FROM
  22. (
  23. SELECT t1.rut AS rut,COUNT(*) AS oc ,0 AS nlic  FROM #temp AS t1
  24. GROUP BY t1.rut
  25. UNION
  26. SELECT t2.rut AS rut,0 AS oc,COUNT(*) AS nlic  FROM #temp2 AS t2
  27. GROUP BY t2.rut
  28. ) AS t3 GROUP BY t3.rut
__________________
What does an execution plan say to t-sql query? Go f**k yourself, if you are not happy with me