【发布时间】:2016-04-14 01:07:00
【问题描述】:
我有两张表如下:
表1:
SectionID SectionName
1 ParentSection1
2 ChildSection1
3 ChildSection2
4 ChildChildSection1
表2:
DependentID ParentID ChildID
1 1 2
2 1 3
3 2 4
输出:
ParentId ParentSectionName ChildSectionName
1 ParentSection1 ChildSection1
1 ParentSection1 ChildSection2
1 ParentSection1 ChildChildSection1
座右铭是将父部分作为子部分的子层次结构。
到目前为止我做了什么:
Select
t.Section as ParentID,t.SectionName as ParentSection,
c.SectionName as ChildSection
from
Table1 t
join
Table2 d on t.SectionID = d.ParentID
right join
c.Table1 on c.SectionID = d.ChildID
where
t.SectionID = 1
SQL 或 Linq 都会有所帮助。请帮帮我。
谢谢
【问题讨论】:
标签: sql sql-server linq tsql linq-to-sql