0

我有 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;
4

0 回答 0