mysql 存储过程中if控制语句的条件判断问题

CREATE PROCEDURE `getTakeNum`(IN catid1 int,IN catid2 int,IN catid3 int,IN userid int,IN newtime int)
begin
select nexttime into @time from gift_user where id=userid;
select t into @num1 from gift_product where uid=userid and cid=catid1 order by t desc limit 0,1;
select t into @num2 from gift_product where uid=userid and cid=catid2 order by t desc limit 0,1;
select t into @num3 from gift_product where uid=userid and cid=catid3 order by t desc limit 0,1;
if @num1 < @time AND @num2 < @time AND @num3 < @time then
update gift_user set nexttime=newtime where id=userid;
end if;
end
为什么这个if条件(if @num1 < @time AND @num2 < @time AND @num3 < @time then)只要有1个成立就执行里面的代码了?难道说不能用并且的方式判断么?如果没有有什么办法?

第1个回答  推荐于2018-03-05
if (@num1 < @time)
AND (@num2 < @time)
AND (@num3 < @time)
then本回答被提问者和网友采纳
第2个回答  2010-03-25
可以,这种方式是对的,是你自己写的有点问题,用if语句时应该把所有的判断语句用小括号()括起来。