SQL Server取消舍入乘法的结果

时间:2014-06-29 14:59:49

标签: sql-server rounding

如果您可以查看以下SQL代码并告诉我如何使SQL服务器不舍入第4个选择列的乘法结果,我将不胜感激:

    select  --tmp1.[Session.Call_TYPE_Assigned] CR,
            tmp2.cnt_match / cast(tmp1.cnt as float)   as precision,
            tmp1.cnt as cnt,
            tmp2.cnt_match / cast(tmp1.cnt as float) * tmp1.cnt


    from 
    ( select [Session.Call_TYPE_Assigned],COUNT(*) as cnt from 
    dbo.CEA_CR CEA_CR
    where CEA_CR.cycle = '4' and CEA_CR.version = '1'
    group by [Session.Call_TYPE_Assigned] )  as tmp1
    ,
    (select [Session.Call_TYPE_Assigned],COUNT(*) as cnt_match from 
    dbo.CEA_CR CEA_CR
    where  [Session.Did_Call_Type_happen_on_this_call]= 'Yes' and CEA_CR.cycle = '4' and CEA_CR.version = '1'
    group by [Session.Call_TYPE_Assigned])  tmp2
    where tmp1.[Session.Call_TYPE_Assigned] = tmp2.[Session.Call_TYPE_Assigned] 

结果集看起来像这样

0.666666666666667 3 2

而2不是0.6 * 3的乘积 感谢

1 个答案:

答案 0 :(得分:0)

我会想:

convert(float,tmp2.cnt_match / cast(tmp1.cnt as float) * tmp1.cnt)

作为选择的最后一行或

convert(float,[precision] * tmp1.cnt)

因为选择的最后一行可能有用。