Skip to content

Instantly share code, notes, and snippets.

@niisar
Created May 19, 2014 21:24
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 niisar/a597124e017de8bcb4c4 to your computer and use it in GitHub Desktop.
Save niisar/a597124e017de8bcb4c4 to your computer and use it in GitHub Desktop.
spin thru family table starting at parent_key is null
WITH RSFC(CK,PK,LVL) AS
( SELECT CHILD_KEY,PARENT_KEY,0 AS LVL FROM FAMILY WHERE PARENT_KEY IS NULL
UNION ALL
SELECT CHILD_KEY,
PARENT_KEY,
LVL+1
FROM RSFC R
INNER JOIN FAMILY F
ON R.CK = F.PARENT_KEY
)
SELECT * FROM RSFC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment