Ver Mensaje Individual
  #6 (permalink)  
Antiguo 22/01/2014, 22:03
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: count de registros donde no coincidan 3 campos

eso lo sacas con un

Código SQL:
Ver original
  1. CREATE TABLE #temp(
  2. id INT,
  3. id1 INT,
  4. id2 INT,
  5. id3 INT
  6. )
  7.  
  8.  
  9.  
  10. INSERT INTO #temp VALUES (1, 11, 4, 2)
  11. INSERT INTO #temp VALUES (1, 11, 6, 1)
  12. INSERT INTO #temp VALUES (1, 36, 10, 2)
  13.  
  14. CREATE TABLE #temp2(
  15. id INT,
  16. id1 INT,
  17. id2 INT,
  18. id3 INT
  19. )
  20.  
  21.  
  22. INSERT INTO #temp2 VALUES (1, 11, 4, 1)
  23. INSERT INTO #temp2 VALUES (1, 11, 4, 2)
  24. INSERT INTO #temp2 VALUES (1, 11, 4, 3)
  25. INSERT INTO #temp2 VALUES (1, 36, 10, 1)
  26. INSERT INTO #temp2 VALUES (1, 36, 10, 2)
  27.  
  28. SELECT SUM(cuantos),id3 FROM
  29. (
  30. SELECT COUNT(*) cuantos,t1.id,t1.id1,t1.id2,t1.id3 FROM #temp AS t1
  31. INNER JOIN #temp2 AS t2 ON (t1.id=t2.id AND t1.id1=t2.id1 AND t1.id2=t2.id2)
  32. WHERE t1.id3=t2.id3
  33. GROUP BY t1.id,t1.id1,t1.id2,t1.id3
  34. ) AS t3 GROUP BY id3
__________________
What does an execution plan say to t-sql query? Go f**k yourself, if you are not happy with me