;with cte as ( select name from t_Column where name='男装' union all select a.name from t_Column a join cte b on a.Fatherid=b.id )select * from cte
select * from t_Column where Fatherid = (select id from t_Column where name ='男装'
WITH cte AS( SELECT id, fatherid, NAME FROM t_column WHERE NAME = N'男装' UNION ALL SELECT a.id, a.fatherid, a.name FROM t_Column AS a, cte AS b WHERE a.fatherid = b.id ) SELECT * FROM cte;
这种方法的效率并不高,推荐楼主使用: TreeID Name 001 男装 001001 背包 这种方式的话 查询数据库 仅使用 like '001%' 即可查询出所有 男装的类别了。
select * from t_Column where Fatherid=(selcet * from name ='男装') 字典表啊~
select * from t_Column where Fatherid=(selcet id from name ='男装') ······是这样·
(
select name from t_Column where name='男装'
union all
select a.name from t_Column a join cte b on a.Fatherid=b.id
)select * from cte
SELECT id,
fatherid,
NAME
FROM t_column
WHERE NAME = N'男装'
UNION ALL
SELECT a.id,
a.fatherid,
a.name
FROM t_Column AS a,
cte AS b
WHERE a.fatherid = b.id
)
SELECT *
FROM cte;
TreeID Name
001 男装
001001 背包 这种方式的话 查询数据库 仅使用 like '001%' 即可查询出所有 男装的类别了。
字典表啊~
······是这样·