1

我有两个要在 Microsoft Access 2003 中合并为一个的查询。

SELECT AttendanceQuery.AttendDate, Count(*) AS Absent
FROM AttendanceQuery
WHERE (((AttendanceQuery.Present)=False))
GROUP BY AttendanceQuery.AttendDate;

SELECT AttendanceQuery.AttendDate, Count(*) AS Enrollment
FROM AttendanceQuery
GROUP BY AttendanceQuery.AttendDate;

一个显示每个日期的总记录,另一个显示标记为缺席的记录。

4

1 回答 1

0

将您的 2 个查询用作子查询。 LEFT JOIN到缺勤子查询的注册子查询...将返回所有AttendDate值的行,无论这些日期是否记录了缺勤。

SELECT e.AttendDate, e.Enrollment, a.Absent
FROM
    (
        SELECT a1.AttendDate, Count(*) AS Enrollment
        FROM AttendanceQuery AS a1
        GROUP BY a1.AttendDate
    ) AS e
    LEFT JOIN
    (
        SELECT a2.AttendDate, Count(*) AS Absent
        FROM AttendanceQuery AS a2
        WHERE a2.Present=False
        GROUP BY a2.AttendDate
    ) AS a
    ON e.AttendDate = a.attendDate;

如果您将从 Access 会话中运行此查询,则可以使用Nz(a.Absent, 0)将 NullAbsent值显示为零。如果从 Access 外部运行查询,请使用IIf(a.Absent Is Null, 0, a.Absent)

于 2013-07-03T17:12:08.687 回答