SQL一直正在执行查询出不了结果
答案:1 悬赏:60 手机版
解决时间 2021-04-16 10:01
- 提问者网友:情歌越听越心酸
- 2021-04-15 11:43
SQL一直正在执行查询出不了结果
最佳答案
- 五星知识达人网友:西岸风
- 2021-04-15 13:01
--方法一
declare @y int,@total int,@z int
declare @startTime datetime=getdate()
set @y=1
set @total=0
while @y<=10000
begin
if(@y%10=0)
begin
set @y=@y+1
continue
end
else
set @total=@total+@y
set @y=@y+1--没有这句的话,你的@y永远等1啊
if(@total>10000000)
begin
break;
end
end
select datediff(ms,@startTime,getdate())
select @total
--方法二
declare @startTime datetime=getdate();
with T
As
(
select 1 As A,1 As Rst
union all
Select A+1,Rst+case when (A+1)%10=0 then 0 else A+1 End From T where Rst<10000000
)
select MAX(Rst) from T
option (MAXRECURSION 10000)
select datediff(ms,@startTime,getdate())
declare @y int,@total int,@z int
declare @startTime datetime=getdate()
set @y=1
set @total=0
while @y<=10000
begin
if(@y%10=0)
begin
set @y=@y+1
continue
end
else
set @total=@total+@y
set @y=@y+1--没有这句的话,你的@y永远等1啊
if(@total>10000000)
begin
break;
end
end
select datediff(ms,@startTime,getdate())
select @total
--方法二
declare @startTime datetime=getdate();
with T
As
(
select 1 As A,1 As Rst
union all
Select A+1,Rst+case when (A+1)%10=0 then 0 else A+1 End From T where Rst<10000000
)
select MAX(Rst) from T
option (MAXRECURSION 10000)
select datediff(ms,@startTime,getdate())
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯