SELECT p1.idpattern , p2.idpattern , COUNT(p1.idtag) count1 , (SELECT COUNT(*) FROM rsdb1.positivepatterns20 PI WHERE pi.iduser = 3 AND pi.idpattern = p2.idpattern ) count2
FROM positivepatterns20 p1, positivepatterns20 p2
WHERE p1.idtag = p2.idtag
AND p1.iduser = 1
AND p2.iduser = 3
GROUP BY 1,2
HAVING count1 < count2
AND count1 = (SELECT COUNT(*) FROM positivepatterns20 P1_sub WHERE P1_sub.iduser = 1 AND P1_sub.idpattern = P1.idpattern);
|