el query final solo te arroja los numeros
exp
56
59
y como tienes el group by al final ya no necesitas el distinct :)
Código SQL:
Ver originalSELECT COUNT(DISTINCT(EXP)),EXP FROM #temp
WHERE (fec1 BETWEEN '01/01/2012' AND '06/30/2012') AND
(fec3 BETWEEN '01/01/2012' AND '06/30/2012') AND (fec3<> '1800-01-01')
AND EXP IN (
SELECT t1.EXP FROM
(SELECT COUNT(*) total, EXP FROM #temp GROUP BY EXP) t1
INNER JOIN (SELECT COUNT(*) total , EXP FROM #temp
WHERE (fec1 BETWEEN '01/01/2012' AND '06/30/2012') AND
(fec3 BETWEEN '01/01/2012' AND '06/30/2012')
GROUP BY EXP) t2 ON t1.EXP=t2.EXP
WHERE t1.total=t2.total
)
GROUP BY EXP
aunque para que necesitas los numeros?? porque segun tu logica siempre seria 1 no???
saludos!