【问题标题】:Count SQL in MS Access在 MS Access 中统计 SQL
【发布时间】:2012-03-29 14:23:33
【问题描述】:

我有一个名为 [Review Results] 的表格,看起来有点像以下:

[Reviewed By]....[Review Date]....[Corrective Action]....[CAR]
John.............1/1/2011.........yes....................yes
John.............2/5/2011.........No.....................yes
John.............2/24/2011........yes....................yes
Bobby............1/1/2011.........No.....................No
Bobby............3/1/2011.........yes....................No  

我正在尝试显示特定时期内审阅者的[Corrective Action] = yes 数量以及特定时期内审阅者的[CAR] = yes 数量。我尝试使用以下 SQL,但它没有给出正确的输出:

select 
[Reviewed By],
Count(IIF([Corrective Action] = yes, 1,0)) as [CAMBRs],
Count(IIF([CAR] = yes,1,0)) as [CARs]

from [Review Results] 

where [Review Date]  between #1/1/2011# and #3/1/2011#

group by
[Reviewed By]  

有人可以使用 SQL 为我指明正确的方向吗?

【问题讨论】:

  • 您也在计算查询中的所有“否”.. 而不是 count 使用 sum.. 这会起作用..
  • 宾果游戏...成功了!谢谢

标签: sql ms-access count


【解决方案1】:
select 
[Reviewed By],
SUM(IIF([Corrective Action] = "yes", 1,0)) as [CAMBRs],
SUM(IIF([CAR] = "yes",1,0)) as [CARs]

from [Review Results] 

where [Review Date]  between #1/1/2012# and #3/1/2012#

group by
[Reviewed By]  

【讨论】:

  • 我应该提一下,[Corrective Action][CAR] 字段是表中的复选框[Review Results]
  • 在这种情况下,您可以使用 Abs([Corrective Action]) 返回 1 或 0。Count(Abs([Corrective Action] )
【解决方案2】:

可能是这样的:

select 
   [Reviewed By],
   SUM(IIF([Corrective Action] = True, 1,0)) as [CAMBRs],
   SUM(IIF([CAR] = True,1,0)) as [CARs]

from [Review Results] 

where [Review Date]  between #1/1/2012# and #3/1/2012#

group by
[Reviewed By]

【讨论】:

  • 这不起作用....如上所述,[Corrective Action][Car] 字段是 [审核结果]表....
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-07-25
  • 2023-03-28
  • 1970-01-01
  • 1970-01-01
  • 2017-02-14
  • 2012-09-23
  • 1970-01-01
相关资源
最近更新 更多