请高手帮忙,让我这个程序跑快点
我的表结构为:ID L1 L2 L3 L4 L5 L6 M
代码的意思是:
查找出每行L1 L2 L3 L4 L5 L6的最大值,如果L1最大,则给M赋值1
如果L2最大,则给M赋值2
以此类推。
我的代码为:
CREATE procedure sel as
declare @index integer
declare @a float
declare @b float
declare @c float
declare @d float
declare @e float
declare @f float
set @index = 1
while(@index < 1297797)
begin
set @a =(select L1 from vv where ID = @index)
set @b =(select L2 from vv where ID = @index)
set @c =(select L3 from vv where ID = @index)
set @d =(select L4 from vv where ID = @index)
set @e =(select L5 from vv where ID = @index)
set @f =(select L6 from vv where ID = @index)
if(@a > = @b AND @a > = @c AND @a > = @d AND @a > =@e AND @a > = @f)
begin
update vv
set M = 1 where ID = @index
end
else if(@b > = @a AND @b > = @c AND @b > = @d AND @b > =@e AND @b > = @f)
begin
update vv
set M = 2 where ID = @index
end
else if(@c > =@a AND @c > = @b AND @c > = @d AND @c > =@e AND @c > = @f)
begin
update vv
set M = 3 where ID = @index
end
else if(@d > = @a AND @d > = @b AND @d > = @c AND @d > =@e AND @d > = @f)
begin
update vv
set M = 4 where ID = @index
end
else if(@e > = @a AND @e > =@b AND @e