1

我有一些看起来相当简单的东西,但这里缺少一些东西。我正在尝试显示所有不同的 [业务流程] 值,并计算每个 [业务流程] 的记录数,其中 [需要更正操作] = TRUE。对于某些 [需要更正操作] = TRUE 的 [业务流程] 值,可能存在零记录,或者值 > 0。这是我正在使用的 SQL:

SELECT  [Business Process], sum([Corrective Action Is Required]) as [Total Corrective Action Is Required]

FROM [Review Results]

WHERE [Corrective Action is Required] in 

(select IIF([Corrective Action Is Required] = TRUE, 1, 0) from [Review Results]) 

GROUP BY [Business Process]

ORDER BY [Business Process];

目前,SQL 在所有记录中显示 [需要采取总纠正措施] 的值为 0。有人可以指出我做错了什么吗?

4

3 回答 3

3

在 Access 中,True=-1 和 False=0,那么如何:

SELECT [Business Process], 
       Sum(Abs([Corrective Action Is Required])) 
          as [Total Corrective Action Is Required]
FROM [Review Results]
GROUP BY [Business Process]

当您有 Group By 时,您不需要 Order By。

于 2012-04-10T14:47:29.630 回答
1

您可以对布尔值求和,但在访问中您会得到否定结果,因为 True = -1 - 所以这应该有效

SELECT  [Business Process], sum(iif([Corrective Action Is Required] = TRUE, 1, 0)) as [Total Corrective Action Is Required]
FROM [Review Results]
GROUP BY [Business Process]
ORDER BY [Business Process]
于 2012-04-10T14:47:34.040 回答
0

这样做不是更容易吗?还记得检查你的基础数据。

SELECT  [Business Process], count([Corrective Action Is Required]) as [Total Corrective Action Is Required]
FROM [Review Results]
WHERE [Corrective Action Is Required] = 1
GROUP BY [Business Process]
ORDER BY [Business Process];
于 2012-04-10T14:25:30.710 回答