访问查询和 Sql 查询结果不匹配

Access Query and Sql Query Results Don't Match

访问查询:

IIf([rptd mean net (g)] > 0, [rptd mean net (g)] - ([Actual Tare Wt (g)] - [Machine Tare Wt (g)]), [Mean Gross (g)] - [actual tare wt (g)]) AS [Net Mean Wt (g)]

这是我访问 click me

得到的结果

SQL查询:

SELECT 
   CASE 
      WHEN [Net Weight Tracking].[Rptd Mean Net (g)] > 0 
         THEN (([Net Weight Tracking].[Rptd Mean Net (g)]) - ([Net Weight Tracking].[Actual Tare Wt (g)])- ([Net Weight Tracking].[Machine Tare Wt (g)])) 
         ELSE ([Net Weight Tracking].[Mean Gross (g)]) - ([Net Weight Tracking].[Actual Tare Wt (g)])  
   END AS [Net Mean Wt (g)]
FROM 
   dbo.[Net Weight Tracking]

这是我为 SQL click me

得到的结果

我的问题是:是什么导致了 [Net Mean Wt (g)] 的差异,这是我的 SQL 案例陈述的问题吗?如果是,我该如何解决我的查询?

您的访问查询中包含的括号造成了混乱:

[rptd mean net (g)]-([Actual Tare Wt (g)]-[Machine Tare Wt (g)])

327-(46.6-47) = 327 - (-.4) = 328.1

您的 SQL 查询没有这些括号。

根据 order of operations.

,括号内的运算在加法和减法之前完成