Using MySQL, how can I make this hierarchy work?
- Parent ID is 100. This parent has ParentID 0.
- The child has the identifier 101. ParentID is 100.
- SubEntity has an identifier of 105. ParentID is 100.
- The child of the subobject has an identifier of 106. Their ParentID is 105.
This request will be connected to iReport. Currently, Subentity and its children do not collapse into Parent.
Here is what I ended up with:
`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`
source share