sql简单运算代码
一、从1加到100
declare @n int, @sum int
set @n=1
set @sum=0
while @n<=100
begin
set @sum=@sum + @n
set @n=@n+1
end
print @sum
二、1到100之间的偶数相加
declare @x int, @sum int
set @x=1
set @sum=0
while @x<=100
begin
set @x=@x+1
if @x%2=0
set @sum=@sum+@x
else
continue
end
print @sum
三、
declare @n int, @sum int
set @n=1
set @sum=0
while @n<=100
begin
set @sum=@sum + @n
set @n=@n+2
end
print @sum
四、
declare @x int, @sum int
set @x=1
set @sum=0
while @x<=100
begin
set @x=@x+1
if @x%3=0
set @sum=@sum+@x
else
continue
end
print @sum
五、
declare @x int, @sum int
set @x=1
set @sum=0
while @x<=100
begin
set @x=@x+1
if @x%5=0
set @sum=@sum+@x
else
continue
end
print @sum
六、
declare @x int, @sum int
set @x=1
set @sum=0
while @x<=100
begin
set @x=@x+1
if @x%7=0
set @sum=@sum+@x
else
continue
end
print @sum
七、
declare @x int, @sum int
set @x=1
set @sum=0
while @x<=100
begin
set @x=@x+1
if @x%11=0
set @sum=@sum+@x
else
continue
end
print @sum
从1的阶乘加到10的阶乘
declare @n int, @total int ,@m int
set @n=1
set @m=1
set @total=0
while @n<=10
begin
set @m=@m*@n
set @total=@total+@m
set @n=@n+1
end
print @total