我有sql语句的5个数写法:但我需要判断6个数甚至是9个数的写法,用以SQL语句。下面是正确的代码。 case when pp2-pp1>pp3-pp2 then case when pp2-pp1>pp4-pp3 then case when pp2-pp1>pp5-pp4 then pp2-pp1-1 else pp5-pp4-1 end else case when pp4-pp3>pp5-pp4 then pp4-pp3-1 else pp5-pp4-1 end end else case when pp3-pp2>pp4-pp3 then case when pp3-pp2>pp5-pp4 then pp3-pp2-1 else pp5-pp4-1 end else case when pp4-pp3>pp5-pp4 then pp4-pp3-1 else pp5-pp4-1 end end end
楼主说的是要用IF ELSE ENDIF写! 我试试:楼主试试对不对function GetMaxP(p1 as double,p2 as double,p3 as double,p4 as double,p5 as double,p6 as double) as doubledim MaxP MaxP = p1 if MaxP >=p2 then '3 if MaxP >=p3 then '4 if MaxP >=p4 then '5 if MaxP >=p5 then '6 if MaxP >=p6 then GetMaxP=MaxP else Maxp=p6 GetMaxP=Maxp end if '6 else '6 MaxP=p5 if MaxP >=p6 then GetMaxP=MaxP else Maxp=p6 GetMaxP=Maxp '6 end if '5 end if else '5 MaxP=p4 if MaxP >=p5 then '6 if MaxP >=p6 then GetMaxP=MaxP else Maxp=p6 GetMaxP=Maxp end if '6 else '6 MaxP=p5 if MaxP >=p6 then GetMaxP=MaxP else Maxp=p6 GetMaxP=Maxp '6 end if '5 end if '4 end if else Maxp=p3 '4 if MaxP >=p4 then '5 if MaxP >=p5 then '6 if MaxP >=p6 then GetMaxP=MaxP else Maxp=p6 GetMaxP=Maxp end if '6 else '6 MaxP=p5 if MaxP >=p6 then GetMaxP=MaxP else Maxp=p6 GetMaxP=Maxp '6 end if '5 end if else '5 MaxP=p4 if MaxP >=p5 then '6 if MaxP >=p6 then GetMaxP=MaxP else Maxp=p6 GetMaxP=Maxp end if '6 else '6 MaxP=p5 if MaxP >=p6 then GetMaxP=MaxP else Maxp=p6 GetMaxP=Maxp '6 end if '5 end if '4 end if '3 end if else MaxP =p2 '3 if MaxP >=p3 then '4 if MaxP >=p4 then '5 if MaxP >=p5 then '6 if MaxP >=p6 then GetMaxP=MaxP else Maxp=p6 GetMaxP=Maxp end if '6 else '6 MaxP=p5 if MaxP >=p6 then GetMaxP=MaxP else Maxp=p6 GetMaxP=Maxp '6 end if '5 end if else '5 MaxP=p4 if MaxP >=p5 then '6 if MaxP >=p6 then GetMaxP=MaxP else Maxp=p6 GetMaxP=Maxp end if '6 else '6 MaxP=p5 if MaxP >=p6 then GetMaxP=MaxP else Maxp=p6 GetMaxP=Maxp '6 end if '5 end if '4 end if else Maxp=p3 '4 if MaxP >=p4 then '5 if MaxP >=p5 then '6 if MaxP >=p6 then GetMaxP=MaxP else Maxp=p6 GetMaxP=Maxp end if '6 else '6 MaxP=p5 if MaxP >=p6 then GetMaxP=MaxP else Maxp=p6 GetMaxP=Maxp '6 end if '5 end if else '5 MaxP=p4 if MaxP >=p5 then '6 if MaxP >=p6 then GetMaxP=MaxP else Maxp=p6 GetMaxP=Maxp end if '6 else '6 MaxP=p5 if MaxP >=p6 then GetMaxP=MaxP else Maxp=p6 GetMaxP=Maxp '6 end if '5 end if '4 end if '3 end if end if end function
case when pp2-pp1>pp3-pp2 then
case when pp2-pp1>pp4-pp3 then
case when pp2-pp1>pp5-pp4 then pp2-pp1-1
else pp5-pp4-1 end
else
case when pp4-pp3>pp5-pp4 then pp4-pp3-1
else pp5-pp4-1 end
end
else
case when pp3-pp2>pp4-pp3 then
case when pp3-pp2>pp5-pp4 then pp3-pp2-1
else pp5-pp4-1 end
else
case when pp4-pp3>pp5-pp4 then pp4-pp3-1
else pp5-pp4-1 end
end
end
我试试:楼主试试对不对function GetMaxP(p1 as double,p2 as double,p3 as double,p4 as double,p5 as double,p6 as double) as doubledim MaxP
MaxP = p1
if MaxP >=p2 then
'3
if MaxP >=p3 then
'4
if MaxP >=p4 then
'5
if MaxP >=p5 then
'6
if MaxP >=p6 then
GetMaxP=MaxP
else
Maxp=p6
GetMaxP=Maxp
end if
'6
else
'6
MaxP=p5
if MaxP >=p6 then
GetMaxP=MaxP
else
Maxp=p6
GetMaxP=Maxp
'6
end if
'5
end if
else
'5
MaxP=p4
if MaxP >=p5 then
'6
if MaxP >=p6 then
GetMaxP=MaxP
else
Maxp=p6
GetMaxP=Maxp
end if
'6
else
'6
MaxP=p5
if MaxP >=p6 then
GetMaxP=MaxP
else
Maxp=p6
GetMaxP=Maxp
'6
end if
'5
end if
'4
end if
else
Maxp=p3
'4
if MaxP >=p4 then
'5
if MaxP >=p5 then
'6
if MaxP >=p6 then
GetMaxP=MaxP
else
Maxp=p6
GetMaxP=Maxp
end if
'6
else
'6
MaxP=p5
if MaxP >=p6 then
GetMaxP=MaxP
else
Maxp=p6
GetMaxP=Maxp
'6
end if
'5
end if
else
'5
MaxP=p4
if MaxP >=p5 then
'6
if MaxP >=p6 then
GetMaxP=MaxP
else
Maxp=p6
GetMaxP=Maxp
end if
'6
else
'6
MaxP=p5
if MaxP >=p6 then
GetMaxP=MaxP
else
Maxp=p6
GetMaxP=Maxp
'6
end if
'5
end if
'4
end if
'3
end if
else
MaxP =p2
'3
if MaxP >=p3 then
'4
if MaxP >=p4 then
'5
if MaxP >=p5 then
'6
if MaxP >=p6 then
GetMaxP=MaxP
else
Maxp=p6
GetMaxP=Maxp
end if
'6
else
'6
MaxP=p5
if MaxP >=p6 then
GetMaxP=MaxP
else
Maxp=p6
GetMaxP=Maxp
'6
end if
'5
end if
else
'5
MaxP=p4
if MaxP >=p5 then
'6
if MaxP >=p6 then
GetMaxP=MaxP
else
Maxp=p6
GetMaxP=Maxp
end if
'6
else
'6
MaxP=p5
if MaxP >=p6 then
GetMaxP=MaxP
else
Maxp=p6
GetMaxP=Maxp
'6
end if
'5
end if
'4
end if
else
Maxp=p3
'4
if MaxP >=p4 then
'5
if MaxP >=p5 then
'6
if MaxP >=p6 then
GetMaxP=MaxP
else
Maxp=p6
GetMaxP=Maxp
end if
'6
else
'6
MaxP=p5
if MaxP >=p6 then
GetMaxP=MaxP
else
Maxp=p6
GetMaxP=Maxp
'6
end if
'5
end if
else
'5
MaxP=p4
if MaxP >=p5 then
'6
if MaxP >=p6 then
GetMaxP=MaxP
else
Maxp=p6
GetMaxP=Maxp
end if
'6
else
'6
MaxP=p5
if MaxP >=p6 then
GetMaxP=MaxP
else
Maxp=p6
GetMaxP=Maxp
'6
end if
'5
end if
'4
end if
'3
end if
end if
end function