select
concat(lv1, '/', lv2, if(lv3 is null, '', concat( '/', lv3 )), if(lv4 is null, '', concat( '/', lv4 ))) as dictory ,
lv1 ,
lv2 ,
ifnull(lv3, lv2) as lv3 ,
ifnull(ifnull(lv4, lv3), lv2) as lv4 ,
paths
from
(
select
a.displayName as lv1 ,
b.displayName as lv2 ,
c.displayName as lv3 ,
d.displayName as lv4 ,
ifnull( ifnull( b.path, c.path ), d.path ) as paths
from
finedb.fine_authority_object a
left join finedb.fine_authority_object b on
a.id = b.parentId
left join finedb.fine_authority_object c on
b.id = c.parentId
left join finedb.fine_authority_object d on
c.id = d.parentId
where
a.parentid = 'decision-directory-root'
order by
a.sortIndex ) a