MySQL数据库语句中设临时变量

set @cat_id=0;
select @cat_id:=cat_id from category where cat_name='shoes';
update products set shop_price=shop_price+7 where cat_id=@cat_id;
update products set market_price=market_price+7 where cat_id=@cat_id;

 @cat_id为临时变量,select @cat_id:=cat_id from category where cat_name='shoes'将查询结果存放到@cat_id中,update语句中用到了@cat_id

你可能感兴趣的:(mysql)