▸_sqlgym

25. Fibonacci Sequence

MediumRecursive CTEsWITH RECURSIVEcarried statemultiple accumulators

A recursive CTE can carry several columns of state forward. The Fibonacci sequence starts 0, 1 and each term is the sum of the previous two.

The table params holds how many terms to produce, n.

Task: return a single column fib with the first n Fibonacci numbers, in order: 0, 1, 1, 2, 3, ....

Tables
Loading schema…
Expected outputrows must come back in this order
Computing expected output…

This is the result for the example data above. On Submit your query is graded against this example plus 4 hidden edge cases 5test cases in all. A sloppy query that only fits the example won't pass.

SQL
⌘/Ctrl+↵ run · ⇧⌘/Ctrl+↵ submit
Run a query to see its output here.