简体   繁体   English

MS Access 2007:计数查询

[英]MS Access 2007 : Count Query

I have created a database which will count the amount of procedures a person has completed and then a query will display the number of times they recieved a particular score for a particular procedure. 我创建了一个数据库,该数据库将计算一个人完成的程序数量,然后查询将显示他们为特定程序获得特定分数的次数。 These scores being "N" "B" and "C". 这些分数是“ N”,“ B”和“ C”。 I use the count function to work this out. 我使用计数功能来解决这个问题。

The procedures are selected from a table. 这些过程是从表中选择的。 Within the query would it be possible for me to output the procedure name [Adult Procedure] in the first column even if there is no data for that procedure. 在查询中,即使没有该过程的数据,我也可以在第一列中输出过程名称[成人过程]。

Here is the query i have produced but it only outputs data for procedures that have data. 这是我产生的查询,但它仅输出包含数据的过程的数据。 I would like it to print all procedure names and if no data is contained to simply add zero to the column. 我希望它显示所有过程名称,并且如果不包含任何数据以仅向该列添加零。

Here is a link to an image the results of the query http://www.flickr.com/photos/mattcripps/6641851977/ I want the first column to include all procedures or which there are about 20. 这是图像查询http://www.flickr.com/photos/mattcripps/6641851977/的链接,我希望第一列包括所有过程或大约20个过程。

TRANSFORM Count(tblEntryData.[Entry ID]) AS [CountOfEntry ID]
SELECT tblEntryData.[Adult Procedure], Count(tblEntryData.[Entry ID]) AS [Total Of Entry ID]
FROM tblEntryData
GROUP BY tblEntryData.[Adult Procedure]
PIVOT tblEntryData.Grade;

Thanks in advance 提前致谢

If the a table of possible [Adult Procedure] existed all you would need is a LEFT JOIN. 如果存在一个可能的[成人程序]表,那么您需要的就是LEFT JOIN。 This would be the recommended solution 这将是推荐的解决方案

TRANSFORM Count(ed.[Entry ID]) AS [CountOfEntry ID]
SELECT ap.[Adult Procedure], Count(ed.[Entry ID]) AS [Total Of Entry ID]
FROM tblAdultProcedure ap
     LEFT JOIN tblEntryData ed
     ON ap.[Adult Procedure ID]  = ed.[Adult Procedure ID]
GROUP BY ap.[Adult Procedure]
PIVOT ed.Grade;

However it is still possible to do it without using another table by deriving the table via another SQL statement (although it will be slower) 但是,仍然可以通过另一个SQL语句派生该表,而无需使用另一个表(尽管这样做会更慢)

TRANSFORM Count(ed.[Entry ID]) AS [CountOfEntry ID]
SELECT ap.[Adult Procedure], Count(ed.[Entry ID]) AS [Total Of Entry ID]
FROM (SELECT DISTINCT [Adult Procedure] FROM tblEntryData) ap
     LEFT JOIN tblEntryData ed
     ON ap.[Adult Procedure]  = ed.[Adult Procedure]
GROUP BY ap.[Adult Procedure]
PIVOT ed.Grade;

Note: you can also put SELECT DISTINCT [Adult Procedure] FROM tblEntryData into a query and then use as you would a table. 注意:还可以将SELECT DISTINCT [Adult Procedure] FROM tblEntryData放入查询中,然后像使用表一样使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM