gpt4 book ai didi

mysql - 在Mysql中对链表进行排序

转载 作者:行者123 更新时间:2023-11-29 01:26:09 25 4
gpt4 key购买 nike

我在 MySQL 中有下表

id  previous
1 null
2 1
3 2
4 3

我想在 mysql -> 中对其进行排序,以便在本例中返回 1,2,3,4。如何做到这一点?

最佳答案

在 MySQL 8.0 中:

with recursive my_node (id) as (
select id from table_a where parent_id is null
union all
select a.id from my_node n join table_a a on n.id = a.parent_id
)
select * from my_node;

关于mysql - 在Mysql中对链表进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50533837/

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