MySQL Set First值是-1还是一个数字?

时间:2014-04-17 02:00:46

标签: mysql sql

我有一个数据表:
player1, player2, player3, player4
它们均为int,默认为-1。我如何设置第一个(player1是第一个,player4是最后一个)-1是一个数字?

例:
player1, player2, player3, player4
-1, -1, -1, -1
player1是-1的第一个值,因此我们将其设置为4.

1 个答案:

答案 0 :(得分:1)

这是你在找什么?

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);