mysql 存储过程中if控制语句的条件判断问题
CREATEPROCEDURE`getTakeNum`(INcatid1int,INcatid2int,INcatid3int,INuseridint,INnewtime...
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个成立就执行里面的代码了?难道说不能用并且的方式判断么?如果没有有什么办法? 展开
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个成立就执行里面的代码了?难道说不能用并且的方式判断么?如果没有有什么办法? 展开
2个回答
展开全部
if (@num1 < @time)
AND (@num2 < @time)
AND (@num3 < @time)
then
AND (@num2 < @time)
AND (@num3 < @time)
then
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
可以,这种方式是对的,是你自己写的有点问题,用if语句时应该把所有的判断语句用小括号()括起来。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询