我有一个表:
col_1 col_2 col_3
10001 apple 3
10001 orange 2
10001 orange 5
10001 orange 8
我如何构造一个SQL语句来得到这样的东西:
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;