eso lo sacas con un
Código SQL:
Ver originalCREATE TABLE #temp(
id INT,
id1 INT,
id2 INT,
id3 INT
)
INSERT INTO #temp VALUES (1, 11, 4, 2)
INSERT INTO #temp VALUES (1, 11, 6, 1)
INSERT INTO #temp VALUES (1, 36, 10, 2)
CREATE TABLE #temp2(
id INT,
id1 INT,
id2 INT,
id3 INT
)
INSERT INTO #temp2 VALUES (1, 11, 4, 1)
INSERT INTO #temp2 VALUES (1, 11, 4, 2)
INSERT INTO #temp2 VALUES (1, 11, 4, 3)
INSERT INTO #temp2 VALUES (1, 36, 10, 1)
INSERT INTO #temp2 VALUES (1, 36, 10, 2)
SELECT SUM(cuantos),id3 FROM
(
SELECT COUNT(*) cuantos,t1.id,t1.id1,t1.id2,t1.id3 FROM #temp AS t1
INNER JOIN #temp2 AS t2 ON (t1.id=t2.id AND t1.id1=t2.id1 AND t1.id2=t2.id2)
WHERE t1.id3=t2.id3
GROUP BY t1.id,t1.id1,t1.id2,t1.id3
) AS t3 GROUP BY id3