Symmetric Pairs

  • + 0 comments

    WITH SMALLER AS ( SELECT DISTINCT X,Y FROM FUNCTIONS WHERE XY ), SAME AS ( SELECT X,Y, COUNT(*) AS COUNTSAME FROM FUNCTIONS WHERE X=Y GROUP BY X, Y ) SELECT SMALLER.X,SMALLER.Y FROM SMALLER JOIN BIGGER ON (SMALLER.X=BIGGER.Y AND SMALLER.Y=BIGGER.X) UNION ALL SELECT DISTINCT X,Y FROM SAME WHERE MOD(COUNTSAME,2)=0 ORDER BY X