在 Sql Server 中除以 2 个数字 [英] Dividing 2 numbers in Sql Server
本文介绍了在 Sql Server 中除以 2 个数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在做 SQL Server 查询计算,除法总是给我零.
I am doing SQL Server query calculations and the division always gives me zero.
SUM(sl.LINES_ORDERED)
, SUM(sl.LINES_CONFIRMED)
, SUM(sl.LINES_CONFIRMED) / SUM(sl.LINES_ORDERED) AS 'Percent'
返回的样本数据集为:
在此示例中,第三行的除法值应为 1.02,但显示为零.这是为什么?
In this example, the third row should have a division value of 1.02, but it's shown as zero. Why is that?
推荐答案
try
SUM(sl.LINES_CONFIRMED) * 1.0 / SUM(sl.LINES_ORDERED)
整数除法只能返回全数,不能返回浮点数.您可以像上面的示例一样强制进行浮点除法.
An integer devision can only return full numbers and not floating point numbers. You can force a floating point division like in the example above.
这篇关于在 Sql Server 中除以 2 个数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文