How to use MYSQL with Case or IF

Asked

Viewed 52 times

-2

This is with CASE that does not work, the idea is simple every day the training of the players is reset to 15, IF the player is VIP, that is to say "time VIP" LESS than the current date, he has only 15 Practices, if not he would be 25, I tried his ways with Case (did not work) If (Also not), someone knows how to make it work?

UPDATE `_personagens` SET `treinos_restantes`= CASE WHEN (tempoVip<CURRENT_TIMESTAMP) THEN "15" ELSE "25" END

UPDATE `_personagens` SET `treinos_restantes`=IF((tempoVip<CURRENT_TIMESTAMP), 15, 25) WHERE Id>0

1 answer

1


The UPDATE can be used with WHERE.

UPDATE `_personagens` SET `treinos_restantes` = "XX" WHERE CURRENT_TIMESTAMP() >= `tempoVip`;
UPDATE `_personagens` SET `treinos_restantes` = "XX" WHERE CURRENT_TIMESTAMP() <= `tempoVip`;
  • Action executes but does not change lines where Vip Time is Higher, CURRENT_TIMESTAMP is the best option?

  • 1

    UPDATE `_personagens` SET `treinos_restantes` = "15" WHERE &#xA;UNIX_TIMESTAMP(CURRENT_TIMESTAMP()) >= `tempoVip`&#xA;UPDATE `_personagens` SET `treinos_restantes` = "25" WHERE UNIX_TIMESTAMP(CURRENT_TIMESTAMP()) <= `tempoVip` It worked because it was UNIX! Thanks

Browser other questions tagged

You are not signed in. Login or sign up in order to post.