2012-08-26 107 views
3
@a = 200 
@b = 1 

@c = @a/@b 

@c將會等於200。我怎麼能制定一個最大值爲@c爲100?限制到最大值

if @c = 99, do nothing 
if @c = 100, do nothing 
if @c > 100, make @c 100 

在SQL中,這是LEAST功能。

回答

-1
case @c 
when 99 
    ## do something 
when 100 
    ## do something 
else 
    @c = 100 if @c > 100 
    # or 
    @c = [@c, 100].min # inspired by minitech answer 
end 
+0

我想你錯過了問題的要點。 – Ryan

+0

@minitech,我錯過了什麼?你能簡要地回答一下 – PriteshJ

+0

我認爲答案促進了良好的代碼習慣,並帶有預期的答案 – PriteshJ