我有两列,都是int的Wins
和Losses
。我有一个计算列WinPercentage
作为decimal(14,3)
,我希望这样:
WinPercentage = (Wins + Losses) / Wins
它的语法是什么?
最佳答案
CREATE TABLE WinLoss
(
TeamId int IDENTITY(1,1) NOT NULL,
Wins int,
Losses int,
WinPercentage AS CASE WHEN wins > 0 THEN (Wins + Losses) / Wins ELSE 0 END
)
关于SQL Server计算列,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4093014/