MS-Access 中的 SQL:使用 COUNT、JOIN 并返回 0
很抱歉发布此内容,但尽管网站上有一些示例,但我无法让我的示例正常工作。
所以我有两个表,如下所示:
电话表
ID | Name | GradeID
1 Richard 1
2 Allan 1
3 Peter
我还有一个成绩表:
ID | Name
1 1
2 2
3 3
4 4
5 5
无论如何,我尝试使用 COUNT() 和 LEFT JOIN 来找出每个成绩在电话表中找到的次数,包括返回任何为 0,通过使用以下查询:
SELECT telephony.GradeID, COUNT(*) AS Total
FROM telephony LEFT JOIN grade
ON telephony.GradeID = grade.ID
GROUP BY telephony.GradeID
ORDER BY 1;
此查询返回所有找到的内容,但不会返回包含 0 个条目的所有成绩:
Grade | Total
1 2
请帮忙。我正在使用 Microsoft Access 2003。
感谢您的帮助。效果很好。
但是,当我尝试合并日期之间时,它仅返回再次找到的成绩。
有什么想法吗?
谢谢
Apologies for posting this but although there are a few examples on the site, I just can't get mine to work.
So I have two tables as follows:
A Telephony table
ID | Name | GradeID
1 Richard 1
2 Allan 1
3 Peter
I also have a Grade table:
ID | Name
1 1
2 2
3 3
4 4
5 5
Anyway I'm trying to use COUNT() and LEFT JOIN to find out the number of times each grade is found in the Telephony table, including returning any which are 0, by using the following query:
SELECT telephony.GradeID, COUNT(*) AS Total
FROM telephony LEFT JOIN grade
ON telephony.GradeID = grade.ID
GROUP BY telephony.GradeID
ORDER BY 1;
This query returns all found but will not return all grades with 0 entries:
Grade | Total
1 2
Please help. I'm using Microsoft Access 2003.
Thanks for all your help. That's working great.
However, when I try to incorporate a DATE BETWEEN it returns only the grades found again.
Any ideas?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为这就是您正在寻找的:
顺便说一句:“名称”对于列来说是一个非常糟糕的名称,因为它是保留字。
I think this is what you are looking for:
BTW: "Name" is a very bad name for a column since it is a reserved word.
由于只有 Grade 表包含所有可用 ID,因此您应该在 SELECT 中使用 Grade.ID 而不是 telephony.GradeID。尝试执行此查询:
As only Grade table contains all available IDs you should use grade.ID in your SELECT instead of telephony.GradeID. Try to execute this query: