访问查询:
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
的结果我的问题是:导致[净均值Wt(g)]差异的原因是,我的SQL案例陈述是否存在问题,如果是这样,我该如何修复我的查询?
答案 0 :(得分:0)
您的访问查询的括号会弄乱它:
[rptd mean net (g)]-([Actual Tare Wt (g)]-[Machine Tare Wt (g)])
327-(46.6-47)= 327 - (-.4)= 328.1
您的SQL查询没有这些括号。
括号内的操作在加法和减法之前按照order of operations完成。