SELECT IF(@maxins < @num_of_ins, @maxins, @num_of_ins)
FROM( SELECT @maxins :=4, @num_of_ins:=10) f1

Ans: 4 [True]
But 10 [False]

最佳答案

第一次发生这种情况..因此,请在选择之前分配var值

set  @maxins =4;
set  @num_of_ins=10;

SELECT IF(@maxins < @num_of_ins, @maxins, @num_of_ins)

10-08 20:20