我有一张桌子:
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
答案 0 :(得分:4)
SELECT *
FROM table t1
JOIN table t2
ON t1.col_1 = t2.col_1
AND t1.col_2 < t2.col_2
答案 1 :(得分:1)
SELECT * FROM table t1 JOIN table t2 ON t1.col_1=t2.col_1;