您的位置:首页 > 博客中心 > 数据库 >

数据库树形结构查询语句

时间:2022-03-14 03:16

表:

gxlsystem.com,布布扣

数据:

gxlsystem.com,布布扣

查询方法:

WITH Tree AS (
    SELECT * FROM TableT AS tt WHERE tt.ID=8
    UNION ALL
    SELECT tt.* FROM Tree AS t INNER JOIN TableT AS tt ON t.ID = tt.pCatID 
)

SELECT * FROM Tree AS t

查出父ID为8的所有节点下的数据

热门排行

今日推荐

热门手游