Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- With CTE as(
- select a.*,
- max(b.num) parent_id
- from accounts a
- left join accounts b on b.num<a.num and b.Hierarchy_level<a.Hierarchy_level
- group by a.num,a.Account_code,a.Account_alias,a.Hierarchy_level
- )
- select c.*,d.num as child_id
- from CTE c, CTE d where c.num=d.parent_id
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement