catspeake
你永远不应该用钱。它是不精确的,而且它是纯粹的垃圾;总是使用十进制/数字。来看看我的意思:DECLARE
@mon1 MONEY,
@mon2 MONEY,
@mon3 MONEY,
@mon4 MONEY,
@num1 DECIMAL(19,4),
@num2 DECIMAL(19,4),
@num3 DECIMAL(19,4),
@num4 DECIMAL(19,4)
SELECT
@mon1 = 100, @mon2 = 339, @mon3 = 10000,
@num1 = 100, @num2 = 339, @num3 = 10000
SET @mon4 = @mon1/@mon2*@mon3 SET @num4 = @num1/@num2*@num3 SELECT @mon4 AS moneyresult,
@num4 AS numericresult产出:2949.0000 2949.8525有些人说你不分钱:这是我用来计算相关性的问题之一,把它换成金钱会产生错误的结果。select t1.index_id,t2.index_id,(avg(t1.monret*t2.monret)
-(avg(t1.monret) * avg(t2.monret)))
/((sqrt(avg(square(t1.monret)) - square(avg(t1.monret))))
*(sqrt(avg(square(t2.monret)) - square(avg(t2.monret))))),current_timestamp,@MaxDate
from Table1 t1 join Table1 t2 on t1.Date = traDate group by t1.index_id,t2.index_id
GCT1015
SQLMenace说钱是不准确的。但你不能把钱乘以/除以金钱!3美元乘以50美分是多少?150美元?你用标量乘以/除以金钱,这应该是十进制。DECLARE@mon1 MONEY,@mon4 MONEY,@num1 DECIMAL(19,4),@num2 DECIMAL(19,4),@num3 DECIMAL(19,4),@num4 DECIMAL(19,4)SELECT@mon1 = 100,
@num1 = 100, @num2 = 339, @num3 = 10000SET @mon4 = @mon1/@num2*@num3SET @num4 = @num1/@num2*@num3SELECT @mon4 AS moneyresult,
@num4 AS numericresult正确结果:moneyresult numericresult
--------------------- ---------------------------------------
2949.8525 2949.8525money只要您不需要超过4个小数位,并且确保您的标量(不代表货币)是decimalS.