You are given a table, Functions, containing two columns: X and Y.
Two pairs (X1, Y1) and (X2, Y2) are said to be symmetric pairs if X1 = Y2 and X2 = Y1.
Write a query to output all such symmetric pairs in ascending order by the value of X. List the rows such that X1 ≤ Y1.
Sample Input
조건
1)(X1, Y1) and (X2, Y2) are said to be symmetric pairs if X1 = Y2 and X2 = Y1.
2) all such symmetric pairs in ascending order by the value of X.
-> ORDER BY X
3)List the rows such that X1 ≤ Y1.
-> HAVING X<=Y
SELECT X AS X1 FROM Functions
INNER JOIN Y AS Y2 ON X1+1=Y2
WHERE X<=Y
ORDER BY X
union
SELECT X AS X2 FROM Functions
INNER JOIN Y AS Y1 ON X2-1=Y1
WHERE X<=Y
ORDER BY X