开发者

SQL JOIN self table

开发者 https://www.devze.com 2023-03-25 01:17 出处:网络
I ha开发者_Python百科ve a table: col_1col_2col_3 10001apple3 10001orange2 10001orange5 10001orange8 How can I construct a SQL statement to get something like this:

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;

0

精彩评论

暂无评论...
验证码 换一张
取 消