计算 MS Access 查询结果中的不同电子邮件地址数
Count Distinct Number of Email Addresses in the Results of a Query in MS Access
我在 MS Access 中查询来自多个 table 的 return 多个列,持续用户指定的时间段。这是针对培训注册数据库的,通常情况下,人们会在给定时间段内多次 类。我需要计算在给定时间范围内接受过培训的人数,但我无法在 Access 中找出任何方法来执行此操作。这是我开始的查询:
SELECT
UsersTABLE.FirstName,
UsersTABLE.LastName,
UsersTABLE.EmailAddress,
UsersTABLE.Department,
UsersTABLE.ActiveUser,
ClassSessionsTABLE.CourseName,
ClassSessionsTABLE.StartTime,
ActivityTABLE.Registered,
ActivityTABLE.Attended
FROM
ClassSessionsTABLE
INNER JOIN
(UsersTABLE
INNER JOIN ActivityTABLE
ON UsersTABLE.[UserID] = ActivityTABLE.[UserID])
ON ClassSessionsTABLE.ClassSessionID = ActivityTABLE.ClassSessionID
WHERE
(((ClassSessionsTABLE.StartTime)
Between [Early Date in MM/DD/YYYY hh:mm:ss AM/PM format]
And [Late Date in MM/DD/YYYY hh:mm:ss AM/PM format])
AND ((ActivityTABLE.Registered)=True))
ORDER BY UsersTABLE.LastName;
从这些查询结果中,我想计算查询中 return 的电子邮件地址 (UsersTABLE.EmailAddress) 的不同数量,以及 return 该数量,以及其余的查询信息,在报表中。我正在使用电子邮件地址,因为我已将其设置为需要 table 中的唯一值。
我在网上看到了一些关于获取不同计数的建议,但是当我尝试这些建议时,我要么得到 UsersTable 中的电子邮件地址总数,要么得到记录总数return由查询编辑。
任何人都可以帮助我计算上述查询 return 的不同电子邮件地址的数量吗?
我不知道有什么方法可以直接将其合并到您的查询中,但以下查询应该会为您提供使用相同条件的唯一电子邮件地址的数量以及原始查询中的所有内容:
SELECT COUNT(*) AS NumEMails FROM
(SELECT
DISTINCT UsersTABLE.EmailAddress
FROM
ClassSessionsTABLE
INNER JOIN
(UsersTABLE
INNER JOIN ActivityTABLE
ON UsersTABLE.[UserID] = ActivityTABLE.[UserID])
ON ClassSessionsTABLE.ClassSessionID = ActivityTABLE.ClassSessionID
WHERE
(((ClassSessionsTABLE.StartTime)
Between [Early Date in MM/DD/YYYY hh:mm:ss AM/PM format]
And [Late Date in MM/DD/YYYY hh:mm:ss AM/PM format])
AND ((ActivityTABLE.Registered)=True))) AS Mails;
我只想展示如何将 luk2302 的子查询添加到现有查询中:
SELECT UsersTABLE.FirstName, UsersTABLE.LastName, UsersTABLE.EmailAddress, UsersTABLE.Department, UsersTABLE.ActiveUser, ClassSessionsTABLE.CourseName, ClassSessionsTABLE.StartTime, ActivityTABLE.Registered, ActivityTABLE.Attended
(SELECT COUNT(*) AS NumEMails FROM
(SELECT
DISTINCT UsersTABLE.EmailAddress
FROM
ClassSessionsTABLE
INNER JOIN
(UsersTABLE
INNER JOIN ActivityTABLE
ON UsersTABLE.[UserID] = ActivityTABLE.[UserID])
ON ClassSessionsTABLE.ClassSessionID = ActivityTABLE.ClassSessionID
WHERE
(((ClassSessionsTABLE.StartTime)
Between [Early Date in MM/DD/YYYY hh:mm:ss AM/PM format]
And [Late Date in MM/DD/YYYY hh:mm:ss AM/PM format])
AND ((ActivityTABLE.Registered)=True))) AS Mails;) AS Expr1
FROM ClassSessionsTABLE INNER JOIN (UsersTABLE INNER JOIN ActivityTABLE ON UsersTABLE.[UserID] = ActivityTABLE.[UserID]) ON ClassSessionsTABLE.ClassSessionID = ActivityTABLE.ClassSessionID
WHERE (((ClassSessionsTABLE.StartTime) Between [Early Date in MM/DD/YYYY hh:mm:ss AM/PM format] And [Late Date in MM/DD/YYYY hh:mm:ss AM/PM format]) AND ((ActivityTABLE.Registered)=True))
ORDER BY UsersTABLE.LastName;
我在 MS Access 中查询来自多个 table 的 return 多个列,持续用户指定的时间段。这是针对培训注册数据库的,通常情况下,人们会在给定时间段内多次 类。我需要计算在给定时间范围内接受过培训的人数,但我无法在 Access 中找出任何方法来执行此操作。这是我开始的查询:
SELECT
UsersTABLE.FirstName,
UsersTABLE.LastName,
UsersTABLE.EmailAddress,
UsersTABLE.Department,
UsersTABLE.ActiveUser,
ClassSessionsTABLE.CourseName,
ClassSessionsTABLE.StartTime,
ActivityTABLE.Registered,
ActivityTABLE.Attended
FROM
ClassSessionsTABLE
INNER JOIN
(UsersTABLE
INNER JOIN ActivityTABLE
ON UsersTABLE.[UserID] = ActivityTABLE.[UserID])
ON ClassSessionsTABLE.ClassSessionID = ActivityTABLE.ClassSessionID
WHERE
(((ClassSessionsTABLE.StartTime)
Between [Early Date in MM/DD/YYYY hh:mm:ss AM/PM format]
And [Late Date in MM/DD/YYYY hh:mm:ss AM/PM format])
AND ((ActivityTABLE.Registered)=True))
ORDER BY UsersTABLE.LastName;
从这些查询结果中,我想计算查询中 return 的电子邮件地址 (UsersTABLE.EmailAddress) 的不同数量,以及 return 该数量,以及其余的查询信息,在报表中。我正在使用电子邮件地址,因为我已将其设置为需要 table 中的唯一值。
我在网上看到了一些关于获取不同计数的建议,但是当我尝试这些建议时,我要么得到 UsersTable 中的电子邮件地址总数,要么得到记录总数return由查询编辑。
任何人都可以帮助我计算上述查询 return 的不同电子邮件地址的数量吗?
我不知道有什么方法可以直接将其合并到您的查询中,但以下查询应该会为您提供使用相同条件的唯一电子邮件地址的数量以及原始查询中的所有内容:
SELECT COUNT(*) AS NumEMails FROM
(SELECT
DISTINCT UsersTABLE.EmailAddress
FROM
ClassSessionsTABLE
INNER JOIN
(UsersTABLE
INNER JOIN ActivityTABLE
ON UsersTABLE.[UserID] = ActivityTABLE.[UserID])
ON ClassSessionsTABLE.ClassSessionID = ActivityTABLE.ClassSessionID
WHERE
(((ClassSessionsTABLE.StartTime)
Between [Early Date in MM/DD/YYYY hh:mm:ss AM/PM format]
And [Late Date in MM/DD/YYYY hh:mm:ss AM/PM format])
AND ((ActivityTABLE.Registered)=True))) AS Mails;
我只想展示如何将 luk2302 的子查询添加到现有查询中:
SELECT UsersTABLE.FirstName, UsersTABLE.LastName, UsersTABLE.EmailAddress, UsersTABLE.Department, UsersTABLE.ActiveUser, ClassSessionsTABLE.CourseName, ClassSessionsTABLE.StartTime, ActivityTABLE.Registered, ActivityTABLE.Attended
(SELECT COUNT(*) AS NumEMails FROM
(SELECT
DISTINCT UsersTABLE.EmailAddress
FROM
ClassSessionsTABLE
INNER JOIN
(UsersTABLE
INNER JOIN ActivityTABLE
ON UsersTABLE.[UserID] = ActivityTABLE.[UserID])
ON ClassSessionsTABLE.ClassSessionID = ActivityTABLE.ClassSessionID
WHERE
(((ClassSessionsTABLE.StartTime)
Between [Early Date in MM/DD/YYYY hh:mm:ss AM/PM format]
And [Late Date in MM/DD/YYYY hh:mm:ss AM/PM format])
AND ((ActivityTABLE.Registered)=True))) AS Mails;) AS Expr1
FROM ClassSessionsTABLE INNER JOIN (UsersTABLE INNER JOIN ActivityTABLE ON UsersTABLE.[UserID] = ActivityTABLE.[UserID]) ON ClassSessionsTABLE.ClassSessionID = ActivityTABLE.ClassSessionID
WHERE (((ClassSessionsTABLE.StartTime) Between [Early Date in MM/DD/YYYY hh:mm:ss AM/PM format] And [Late Date in MM/DD/YYYY hh:mm:ss AM/PM format]) AND ((ActivityTABLE.Registered)=True))
ORDER BY UsersTABLE.LastName;