2

这是针对 SqlCe 的,我正在尝试更新表并为获胜者设置 won +=1,为失败者设置 lost =1。我知道我可以使用两个不同的更新语句来做到这一点,但我想知道是否可以在更新失败者“丢失”值的同时更新获胜者“赢得”值。

基本上就是这个样子,

UPDATE player SET won = won +1 WHERE id = 0
UPDATE player SET won = lost +1 WHERE id = 1
4

1 回答 1

1

这不漂亮,但它有效

UPDATE player SET won = won + CASE WHEN id = 0 THEN -1 ELSE 1 END WHERE id in (0,1)

我个人会坚持使用两个更新声明

于 2012-04-23T03:53:13.900 回答