gpt4 book ai didi

mysql - SQL JOIN 自表

转载 作者:太空宇宙 更新时间:2023-11-03 10:25:04 24 4
gpt4 key购买 nike

我有一张 table :

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

关于mysql - SQL JOIN 自表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6921224/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com