Skip to content

Instantly share code, notes, and snippets.

@Kcko
Created December 23, 2018 12:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kcko/8c9ab3e1ef90529fd79e5babd01fa77e to your computer and use it in GitHub Desktop.
Save Kcko/8c9ab3e1ef90529fd79e5babd01fa77e to your computer and use it in GitHub Desktop.
select l0.catID,
concat(
case when l5.catID is null then '' else concat(l5.category, '/') end
, case when l4.catID is null then '' else concat(l4.category, '/') end
, case when l3.catID is null then '' else concat(l3.category, '/') end
, case when l2.catID is null then '' else concat(l2.category, '/') end
, case when l1.catID is null then '' else concat(l1.category, '/') end
, l0.category)
from catcat l0
left join catcat l1 on l0.parentID=l1.catID
left join catcat l2 on l1.parentID=l2.catID
left join catcat l3 on l2.parentID=l3.catID
left join catcat l4 on l3.parentID=l4.catID
left join catcat l5 on l4.parentID=l5.catID
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment