计算活动参与者总数

发布于 2024-12-10 16:34:01 字数 691 浏览 0 评论 0原文

我正在尝试确定参加特定团体主办的活动的总人数。

我想显示与会者总数、允许的最大出席人数、活动标题、活动日期和活动联系人。我以不同的方式尝试了以下查询,但在 MS Access 2007 中不断出现“输入参数值”对话框。我需要更改什么?

SELECT sum(eventAttendance.attended) AS attendanceTotal, events.max, events.title, events.date, events.eventContact, events.unit
    FROM (client INNER JOIN eventAttendance ON client.clientID=eventAttendance.clientID) INNER JOIN events ON eventAttendance.ID=events.id
    WHERE events.unit='CTL'and eventAttendance.attended = 'yes'
    GROUP BY attendanceTotal, events.max, events.title, events.date, events.eventContact, events.unit;

谢谢。

表关系

I am attempting to determine the total number of people who attended events hosted by a specific group.

I want to display the total number of attendees, the maximum attendance allowed, the event title, event date, and the event contact person. I tried the following query in different ways, but keep getting the "enter paramenter value" dialog box in MS Access 2007. What do I need to change?

SELECT sum(eventAttendance.attended) AS attendanceTotal, events.max, events.title, events.date, events.eventContact, events.unit
    FROM (client INNER JOIN eventAttendance ON client.clientID=eventAttendance.clientID) INNER JOIN events ON eventAttendance.ID=events.id
    WHERE events.unit='CTL'and eventAttendance.attended = 'yes'
    GROUP BY attendanceTotal, events.max, events.title, events.date, events.eventContact, events.unit;

Thank you.

Table Relationships

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼眸里的那抹悲凉 2024-12-17 16:34:01
SELECT
    events.[max],
    events.title,
    events.[date],
    events.eventContact,
    events.unit,
    Count(eventAttendance.attended) AS attendanceTotal
FROM
    (client INNER JOIN eventAttendance
    ON client.clientID=eventAttendance.clientID)
    INNER JOIN events ON eventAttendance.ID=events.id
WHERE
        events.unit='CTL'
    AND eventAttendance.attended = 'yes'
GROUP BY
    events.[max],
    events.title,
    events.[date],
    events.eventContact,
    events.unit;

我将聚合函数从 Sum() 更改为 Count()。请注意,聚合函数不包含在 GROUP BY 子句中 --- GROUP BY 仅列出确定组的字段(或字段表达式),任何聚合函数。

我还在字段名称 max 和 date 周围添加了方括号,因为它们都是 保留字 --- 将名称降低了数据库引擎混淆的风险。

编辑:显示关系的图片还显示您有其他保留字作为字段名称。建议您下载 Allen Browne 的 Database Issue Checker Utility 并用它检查您的应用程序。它会警告您有关保留字和其他潜在“陷阱”问题的信息。

SELECT
    events.[max],
    events.title,
    events.[date],
    events.eventContact,
    events.unit,
    Count(eventAttendance.attended) AS attendanceTotal
FROM
    (client INNER JOIN eventAttendance
    ON client.clientID=eventAttendance.clientID)
    INNER JOIN events ON eventAttendance.ID=events.id
WHERE
        events.unit='CTL'
    AND eventAttendance.attended = 'yes'
GROUP BY
    events.[max],
    events.title,
    events.[date],
    events.eventContact,
    events.unit;

I changed the aggregate function from Sum() to Count(). Notice the aggregate function does not get included in the GROUP BY clause --- the GROUP BY lists only the fields (or field expressions) which determine the groups, NOT any aggregate functions.

I also added square brackets around the field names max and date because those are both reserved words --- bracketing the names reduces the risk of confusing the database engine.

Edit: Your picture which shows the relationships also shows you have additional reserved words as field names. Suggest you download Allen Browne's Database Issue Checker Utility and check your application with it. It will warn you about reserved words and also other potential "gotcha" issues.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文