sql使用语句求0至200的偶数之和
答案:4 悬赏:10 手机版
解决时间 2021-04-06 00:24
- 提问者网友:暮烟疏雨之际
- 2021-04-05 04:48
sql使用语句求0至200的偶数之和
最佳答案
- 五星知识达人网友:野慌
- 2021-04-05 05:00
DECLARE @i int,@s int
SELECT @i=2,@s=0
WHILE @i<=200
BEGIN
SELECT @s=@s+@i
SELECT @i=@i+2
END
PRINT '200以内的偶数之和为:'+CAST(@s AS char)
SELECT @i=2,@s=0
WHILE @i<=200
BEGIN
SELECT @s=@s+@i
SELECT @i=@i+2
END
PRINT '200以内的偶数之和为:'+CAST(@s AS char)
全部回答
- 1楼网友:怀裏藏嬌
- 2021-04-05 07:59
DECLARE @i int,@s int
SELECT @i=2,@s=0
WHILE @i<=200/2
BEGIN
SELECT @s=@s+@i
SELECT @i=@i+2
END
SELECT @i=2,@s=0
WHILE @i<=200/2
BEGIN
SELECT @s=@s+@i
SELECT @i=@i+2
END
- 2楼网友:青尢
- 2021-04-05 06:47
oracle数据库:
SELECT SUM(rn)
FROM
( SELECt rownum rn FROM dual CONNECT BY rownum<=200
)
WHERe mod(rn,2)=0;
SELECT SUM(rn)
FROM
( SELECt rownum rn FROM dual CONNECT BY rownum<=200
)
WHERe mod(rn,2)=0;
- 3楼网友:山有枢
- 2021-04-05 06:36
SQL SERVER版:
DECLARE @i int,@s int
SET @i=2
SET @s=0
WHILE @i<=200
BEGIN
SET @s=@s+@i
SET @i=@i+2
END
SELECt '200以内的偶数之和为:'+ CONVERT(VARCHAR,@s)
DECLARE @i int,@s int
SET @i=2
SET @s=0
WHILE @i<=200
BEGIN
SET @s=@s+@i
SET @i=@i+2
END
SELECt '200以内的偶数之和为:'+ CONVERT(VARCHAR,@s)
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯