斐波那契数列(Fibonacci sequence)的T-SQL实现
;WITH T AS ( SELECT 1 AS NUM, CAST(1 AS BIGINT) AS curr, CAST(NULL AS BIGINT) AS prv UNION ALL SELECT curr.NUM + 1 AS NUM, CAST(CASE WHEN prv IS NULL THEN curr ELSE curr + prv END AS BIGINT) AS curr, CAST(curr AS BIGINT) AS prv FROM T curr WHERE CAST(CASE WHEN prv IS NULL THEN curr + 1 ELSE curr + prv END AS BIGINT) <= CAST(POWER(2,16) AS BIGINT) * CAST(POWER(2,16) AS BIGINT)/2 ) SELECT curr FROM T