I have an ammo
table, and when data is added to this table, the rows where the price
field is greater than 1000 should decrease by 50. But this does not happen:
delimiter & create trigger LowPriceToAmmo after insert on ammo for each row begin declare i int; declare countI int; declare countAmmo int; select count(ammo.price) into countI from ammo; set @i:= 1; while @i > countI do select ammo.price into countAmmo from ammo where id = @i; if(countAmmo > 1000) then update ammo set price = price - 50 where id = @i; end if; set @i:= @i +1; end while; end&
ammo
table, it is necessary that the ALL records withprice>=1000
in the table are reduced by 50? Do I understand correctly? - cyadvertUPDATE
?UPDATE ammo SET price=price-50 WHERE price>=1000
? - cyadvert@i
variable@i
nothing to do withi
, which is declared declare and tries to be used in while. variables with a dog and variables without a dog are made for completely different tasks. - Mike