开发者

SQL Server Calculated Column

开发者 https://www.devze.com 2023-01-23 04:47 出处:网络
I have two columns, both int\'s, Wins and Losses. I have a calculated column WinPercentage as a decimal(14,3), I want this to be:

I have two columns, both int's, Wins and Losses. I have a calculated column WinPercentage as a decimal(14,3), I want this to be:

WinPercentage = (Wins + 开发者_如何学PythonLosses) / Wins

What's the syntax for that?


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

精彩评论

暂无评论...
验证码 换一张
取 消