我有一个数据表:player1, player2, player3, player4
它们都是默认为int
的-1
。我该如何设置第一个(-1为player1
,player4
为最后一个)数字-1?
例:player1, player2, player3, player4
-1, -1, -1, -1
player1
是第一个值为-1的值,因此我们将其设置为4。
最佳答案
这是你想要的?
update table t
set player1 = (case when player1 = -1
then <a number> else player1 end),
player2 = (case when player1 <> -1 and player2 = -1
then <a number> else player2 end),
player3 = (case when player1 <> -1 and player2 <> -1 and player3 = -1
then <a number> else player3 end),
player4 = (case when player1 <> -1 and player2 <> -1 and player3 <> -1 and player4 = -1
then <a number> else player4 end);
关于mysql - MySQL Set First值是否为-1?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23123313/