无法获得子查询工作

时间:2013-10-16 00:41:38

标签: sql ms-access ms-access-2010

我有2个问题可以自己运行,但我一直在努力让它们一起工作。我有一张审核表,我正在试图通过审核员来计算审核。我正在使用表格来获取日期范围和审计员。审计员位于名为tblUser的表中。主表是tblParatransitPullOutAudit。此表中有一个名为AuditId的字段,它告诉我每个记录属于哪个审计。可能有许多具有相同审计ID的记录,这些记录计为1次审计。我想计算按日期范围和审计员进行的审计数量。任何帮助将不胜感激。

SELECT 
    t.Contractor, 
    Count(t.PK_ParapullOut) AS Audits
FROM 
    tblUser 
    INNER JOIN 
    tblParatransitPullOutAudit AS t 
        ON tblUser.PK_User = t.Auditor
WHERE ((t.AuditDate) Between forms!frmTotalAuditsDateRangeAuditor!txbStartDate.value And forms!frmTotalAuditsDateRangeAuditor!txbEndDate.value) 
    And ((tblUser.PK_User)=Forms!frmTotalAuditsDateRangeAuditor!cboAuditor.value)
GROUP BY Contractor;


SELECT 
    p.Contractor, 
    Count(p.AuditID) AS Audits
FROM 
    (
        SELECT DISTINCT 
            p.Auditor, 
            p.AuditDate, 
            p.contractor, 
            p.auditid 
        FROM tblParatransitPullOutAudit AS p
    )  AS Total
WHERE ((p.AuditDate) Between forms!frmTotalAuditsDateRange!txbStartDate.value And forms!frmTotalAuditsDateRange!txbEndDate.value)
GROUP BY p.Contractor;

0 个答案:

没有答案