当前位置:Gxlcms >
数据库问题 >
SQL Server ->> 斐波那契数列(Fibonacci sequence)
SQL Server ->> 斐波那契数列(Fibonacci sequence)
时间:2021-07-01 10:21:17
帮助过:4人阅读
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
SQL Server ->> 斐波那契数列(Fibonacci sequence)
标签: