[递归]可能会用到
WITH
RECURSIVE cteTree AS
(
SELECT
pc.id,
pc.parent_id,
pc.name,
CONCAT(pc.id,'') AS nodePath,
1 lev
FROM
product_category pc
WHERE
id = 1
UNION ALL
SELECT
pc1.id,
pc1.parent_id,
pc1.name,
CONCAT(c.nodePath,'/',pc1.id) AS nodePath,
c.lev + 1
FROM
cteTree c
INNER JOIN
product_category pc1
ON
pc1.parent_id = c.id
)
--SELECT split_part(nodePath,'/',2) as id FROM cteTree
SELECT
*
FROM
cteTree