我有两列,都是int的WinsLosses。我有一个计算列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/

10-11 05:13