More for my amusement than anything; the following t-sql query utilizing a common table expression can be used to show the beginning of the Fibonacci sequence, as well as it’s convergence and relationship with the golden ratio.

;WITH [Fibonacci] AS
(
	SELECT 
		0 AS [Number],
		1 AS [NextNumber],
		1 AS [Index],
		CAST(NULL AS FLOAT) AS [Ratio]
	UNION ALL
	SELECT
		[NextNumber],
		[Number] + [NextNumber],
		[Index] + 1,
		CASE
			WHEN [Number] = 0 THEN NULL
			ELSE CAST([NextNumber] AS FLOAT) / [Number]
		END
	FROM
		[Fibonacci]
	WHERE
		[Index] < 25
)
SELECT
	[Number],
	[Ratio] AS [Ratio approaching golden ratio]
FROM
	[Fibonacci]

Note that this is a more simple version of the fibonacci CTE found on Manoj Pandey’s blog. I’ve simplified his CTE, removing an unnecessary field, only to complicate it up again with the additional ratio calculation.