用SQL编程,求1到10的阶乘的和?急

2024-12-27 10:56:45
推荐回答(2个)
回答1:

oracle 一条语句:

select sum(serial_mul) from (
select rownum rn, power(10, sum(log(10, rownum))over(order by rownum)) serial_mul,
sum(rownum)over(order by rownum) serial_add
from dual connect by rownum <= 10)

回答2:

begin
declare @sum int
declare @nj int
declare @n int
set @n=1
set @nj=1
set @sum=0
while @n<=10
begin
select @sum=@sum+@nj
select @n=@n+1
select @nj=@nj*@n
end
end
print @sum