Skip to content

Instantly share code, notes, and snippets.

@pv8
Last active December 20, 2015 21:19
Show Gist options
  • Save pv8/6196907 to your computer and use it in GitHub Desktop.
Save pv8/6196907 to your computer and use it in GitHub Desktop.
Fibonacci sequence with SQL (Common Table Expression)
-- == Fibonacci Example ==
WITH RECURSIVE fibo (a, b) AS (
SELECT 0, 1 -- Initial Subquery
UNION ALL
SELECT b, a+b FROM fibo -- Recursive Subquery
WHERE b < 100
)
SELECT a FROM fibo;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment