色婷婷狠狠18禁久久YY,CHINESE性内射高清国产,国产女人18毛片水真多1,国产AV在线观看

mysql 查詢 所有父節點

林子帆2年前11瀏覽0評論

在MySQL數據庫中,查詢所有父節點是一項常見的任務。下面是一些示例操作,幫助你了解如何查詢所有父節點。

-- 示例1:查詢指定節點的父節點
SELECT * FROM `table_name` WHERE `id` = '指定節點的id'
-- 示例2:查詢所有節點的父節點
SELECT * FROM `table_name` WHERE `is_parent` = '1'
-- 示例3:查詢所有節點的父節點,并按照id順序排序
SELECT * FROM `table_name` WHERE `is_parent` = '1' ORDER BY `id` ASC
-- 示例4:查詢指定節點的所有父節點
WITH RECURSIVE cte AS (
SELECT * FROM `table_name` WHERE `id` = '指定節點的id'
UNION ALL
SELECT `table_name`.* FROM `table_name` JOIN cte ON `table_name`.`id` = `cte`.`pid`
)
SELECT * FROM cte
-- 示例5:查詢所有節點的所有父節點
WITH RECURSIVE cte AS (
SELECT * FROM `table_name` WHERE `is_parent` = '1'
UNION ALL
SELECT `table_name`.* FROM `table_name` JOIN cte ON `table_name`.`id` = `cte`.`pid`
)
SELECT * FROM cte