27,579
社区成员
发帖
与我相关
我的任务
分享
with t as
(
select a.CategoryName,b.Title,b.Content
from ArticleCategory a
join Article b on a.CategoryId=b.CategoryId
where a.CategoryName='你提供的类别名'
union all
select a.CategoryName,b.Title,b.Content
from ArticleCategory a
join Article b on a.CategoryId=b.CategoryId
join t c on a.ParentId=c.CategoryId
)
select * from t
create proc sp_name (@CategoryId int)
as
with cte as(
select a.CategoryName,b.*,0 as levl from ArticleCategory a, Article b
where a.CategoryId=b.@CategoryId
union all
select a.CategoryName,b.*, levl+1 from ArticleCategory a, Article b, cte c
where a.CategoryId=b.CategoryId and a.ParentId=c.CategoryId
)
select * from cte