我有一个数据表:
player1, player2, player3, player4
它们均为int
,默认为-1
。我如何设置第一个(player1
是第一个,player4
是最后一个)-1是一个数字?
例:
player1, player2, player3, player4
-1, -1, -1, -1
player1
是-1的第一个值,因此我们将其设置为4.
答案 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);