Symmetric Pairs

  • + 2 comments

    Here is a basic mySQL solution without JOIN, OVER, UNIO, ROW_NUMBER(), LEAD. It only singly counts pairs x,x if they occur exactly twice, so it fails for triple occurrence, but this amount of repetition is not in the data and its handling is not specified in the statement.

    SELECT DISTINCT O.x,O.y FROM Functions AS O
    WHERE (O.x <= O.y) AND (O.x=O.y) <
    (SELECT COUNT(*) FROM Functions AS I WHERE I.x=O.y AND I.y=O.x)
    ORDER BY O.x,O.y;