我想在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;
一个显示每个日期的总记录,另一个显示标记为缺席的记录。
答案 0 :(得分: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)
将空Absent
值显示为零。如果从Access外部运行查询,请使用IIf(a.Absent Is Null, 0, a.Absent)