Sql 递归
USE RJSite
GO
WITH temp
AS ( SELECT *
FROM dbo.VideoType
WHERE ID = 1 --要查询的子类ID
UNION ALL
SELECT v.*
FROM VideoType AS v ,
temp
WHERE v.PID = temp.ID -- 查询所有子类
)
SELECT *
FROM temp;
WITH temp2
AS ( SELECT *
FROM dbo.VideoType
WHERE ID = 9 --要查询的子类ID
UNION ALL
SELECT v.*
FROM VideoType AS v ,
temp2
WHERE v.ID = temp2.PID -- 查询所有父类
)
SELECT *
FROM temp2
有些事现在不做,一辈子都不会做了