SQL Server 计算列
我有两列,都是整数,Wins
和 Losses
。我有一个计算列 WinPercentage
作为 decimal(14,3)
,我希望它是:
WinPercentage = (Wins + Losses) / Wins
它的语法是什么?
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 + Losses) / Wins
What's the syntax for that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要在现有表中创建计算列,请使用“ALTER TABLE”。
胜率的计算公式为
胜率 = (胜数 / (胜数 + 负数)) * 100
当胜负总数为 0 时,利用 NULLIF 函数来防止被零除的问题。
希望!这很有帮助。
To create a calculated column into the existed table, then use "ALTER TABLE".
The formula for win percentage is
Win Percentage = (Wins / (Wins + Losses)) * 100
When the total of wins and losses is 0, the NULLIF function is utilized to prevent division by zero problems.
Hope! it's helpful.