0

I need to decrease all values in an integer column. When one of them equals to 0, it should stop to decrease that value and continue to decrease all other values in that column. I do this with event schedule in Mysql. This works:

UPDATE dbname.tablename SET money = money - 1;

But if I add if statement, it does not works

IF dbname.tablename.money > 0 THEN
UPDATE dbname.tablename SET money = money - 1;
END IF
Vit
  • 396
  • 2
  • 7
  • 16

1 Answers1

0

You just need to limit the execution to rows containing a value in money greater than zero

UPDATE dbname.tablename SET money = money - 1 WHERE money>0;
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149