SQL script to return the fabinaci series
We can easily return the factorial of a number by using CTE.
Find below the script to do that:
Find below the script to do that:
WITH
Fibonaci
(N,
Fib)
AS
(
SELECT
1,
1
UNION
ALL
SELECT
Fib,
(N+Fib)
FROM
Fibonaci
WHERE
N
<
100
)
SELECT
Fib
FROM
Fibonaci
Result:
If we see the above script, first it will return 1, 1 and it will loop through the Fact CTE to get the fibonaci series till the given number
Labels: fibonaci series in sql, SQL Basics, sql interview questions, SQL Learning
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home