SQL JOIN self table
I ha开发者_Python百科ve a table:
col_1 col_2 col_3
10001 apple 3
10001 orange 2
10001 orange 5
10001 orange 8
How can I construct a SQL statement to get something like this:
col_1 col_2 col_3 col_2 col_3
10001 apple 3 orange 2
10001 apple 3 orange 5
10001 apple 3 orange 8
SELECT *
FROM table t1
JOIN table t2
ON t1.col_1 = t2.col_1
AND t1.col_2 < t2.col_2
SELECT * FROM table t1 JOIN table t2 ON t1.col_1=t2.col_1;
精彩评论