Skip to content

Instantly share code, notes, and snippets.

@niisar
Created May 19, 2014 21:19
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/ddfe3574a75924a1669c to your computer and use it in GitHub Desktop.
Save niisar/ddfe3574a75924a1669c to your computer and use it in GitHub Desktop.
compute 4! using a recursive with clause
WITH RSFC(ITERATION,RUNNING_FACTORIAL) AS
( SELECT NUM AS ITERATION, 1 AS RUNNING_FACTORIAL FROM NUMBERS WHERE NUM =1
UNION ALL
SELECT R.ITERATION +1,
R.RUNNING_FACTORIAL * B.NUM
FROM RSFC R
INNER JOIN NUMBERS B
ON (R.ITERATION+1) = B.NUM
)
SELECT iteration,running_factorial FROM rsfc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment