MS Access中的SQL计数
我有一个名为[Review Results]的表,看起来有点像下面的:MS Access中的SQL计数,sql,ms-access,count,Sql,Ms Access,Count,我有一个名为[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...
[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为我指出正确的方向吗?可能是这样的:
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]
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]字段是表[Review Results]中的复选框,在这种情况下,您可以使用Abs([Corrective Action])返回1或0<代码>计数(Abs([纠正措施])您正在计算查询中的所有“否”。。。。