sql 树形递归查询

sql 树形递归查询:

with ProductClass(ClassId,ClassName) as
(    
select ClassId,ClassName from Classes where ClassId = 31281
union all
select c.ClassId,c.ClassName from Classes c inner join ProductClass parent on c.ParentClassId = parent.ClassId
)
select  c.ClassId, c.ClassName, m.ProductId, m.ProductName
from ProductClass c
 inner join Products m on c.ClassId = m.ClassId

 

posted @ 2019-07-24 13:52  大空白纸  阅读(2165)  评论(0编辑  收藏  举报