Created
May 19, 2014 21:24
-
-
Save niisar/a597124e017de8bcb4c4 to your computer and use it in GitHub Desktop.
spin thru family table starting at parent_key is null
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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