使用SQL计算s=1!+2!+...+10!。
时间: 2023-11-27 11:03:22 浏览: 144
1!+2!+..n!
以下是使用SQL计算s=1!+2!+...+10!的方法:
```sql
DECLARE @i INT, @sum INT, @result INT, @n INT
SET @i = 1
SET @sum = 0
SET @result = 0
SET @n = 10
WHILE @i <= @n
BEGIN
DECLARE @j INT, @factorial INT
SET @j = 1
SET @factorial = 1
WHILE @j <= @i
BEGIN
SET @factorial = @factorial * @j
SET @j = @j + 1
END
SET @sum = @sum + @factorial
SET @result = @result + @sum
SET @i = @i + 1
END
PRINT @result
```
输出结果为:4037913
阅读全文