我有这样的表
id name pid
101 Animal null
102 Dog 101
103 pug 102
我想要动物>狗>哈巴狗
答案 0 :(得分:0)
我认为这样的事情适合你,因为我不知道你的RDBMS可能需要一些改变
WITH NewAnimal
AS (SELECT CAST((a.Desc + '>' + t.Name) AS VARCHAR(1000)) AS "Desc"
FROM Table AS t
JOIN NewAnimal AS a
ON t.PID = a.id
)
SELECT * FROM NewAnimal