使用MySQL如何让这个层次结构起作用?如何让这个亲子关系有效?
- 父的ID是100。这父具有0
- 儿童的PARENTID具有101. PARENTID的ID为100。
- 子实体具有105的ID的PARENTID为100
- 儿童子实体的具有106及其PARENTID的ID是105
这个查询将被插入到iReport的。目前Subentity和它的孩子不会卷入Parent。
这是我结束了去:
`Select
case
when FC.ParentType = 'PARENT' then FC.FundCode
when FB.ParentType = 'PARENT' then FB.FundCode
when F.ParentType = 'PARENT' then F.FundCode
else 0 end as `ParentID`,
case
when FB.ParentType = 'SUBFUND' then FB.FundCode
when F.ParentType = 'SUBFUND' then F.FundCode
else 0 end as `SubfundID`,
case
when FB.ParentType = 'CHILD' then FB.FundCode
when F.ParentType = 'CHILD' then F.FundCode
else 0 end as `Children`,
F.FundName
From Fund F
join Fund FB on F.ParentId = FB.FundCode
join Fund FC on FB.ParentID = FC.FundCode`
为了澄清,你有一个父母记录涉及到另一行的父母ID? – tmesser
如果您可以告诉我们,您已经尝试了什么,这将会有所帮助。 – Darvex
@YYY要试着回答你的两个问题,数据不在基金表中。母基金有子基金和一个子基金,也有子基金。现在这份报告的作用就是家长的孩子们聚集起来。然而,子基金和它的孩子只会卷到他们需要汇总到父母的子基金。现在我把所有的资金从表格中删除,只需要在条款 – nEWbie