jeudi 25 avril 2019

MySQL: increment and reset a variable in IF statement when updating row

In the commande below:

SET @var=1; UPDATE characters SET tmp =  IF(isRadical=1, @var=1, @var:=@var+1);

I'm expecting @var and tmp column to be reset to 1 when the column isRadical=1 for a row, and incrementing otherwise. But what I get instead is that tmp is always incremented and never reset to 1, when isRadical=1, then tmp is set to 0 for the given row only.

What's wrong in this command ?

Aucun commentaire:

Enregistrer un commentaire