- ALL
- java33
- linux32
- 工具17
- 其他14
- 数据库7
- vue5
- git5
- nas5
- 前端5
- ai3
- framework3
- windows3
- app2
- 脚本2
- docker2
- hexo2
- maven2
- 智能家居2
- 小程序2
- spring2
- 资源1
- api1
- mysql1
- 安全1
- markdown1
- question1
- python1
- 运维1
- 数据结构1
- 数据传输1
- nginx1
在mysql中查询最终组装为树形结构的数据
根据某一个id查出所有父级、祖级、包括当前节点 1234567891011121314151617SELECT T2.* FROM ( SELECT @r AS _id, ( SELECT @r := parent_id FROM sys_city WHERE id = _id ) AS parent_id, @l := @l + 1 AS lvl FROM ( SELECT @r := 真实id, @l := 0 ) vars, sys_city h WHERE @r <> 0 ) T1 JOIN sys_city T2 ON T1._id = T2.id ORDER BY T1.lvl DESC 根据某一个父级id查出所有子级、孙级、包括当前节点 1234567891011121314151617SELECT id, name, parent_id FROM (SELECT t1.id, IF(FIND_IN_SET(parent_id,...