oracle自身关联查询父类别与子类别

针对于一个表中含有parentid的数据表,要想查询parentid所对应的类别名称,就需要数据表的自身关联。

如下图是数据表:



可以采用如下sql:

select 
s.id,
s.category,
f.id as parent_id,
f.category as parent_category
from t_goodscategory s left join t_goodscategory f on (s.parentid=f.id)
where f.id<>0

查询结果为:


猜你喜欢

转载自blog.csdn.net/qq_36795474/article/details/79977441
今日推荐