我对多表查询有一点问题。(RDBMS:访问)
这是数据库模式:(此查询中仅使用 S_Cards、Books、Authors、Student 表)S_Cards 是 Student 图书订单(在图书馆中)。
查询:选择学生中最受欢迎的作者以及该作者在图书馆订购的书籍数量。
虽然我可以在一个查询中获得这样的订单+作者列表:
SELECT
Students.FirstName & " " & Students.LastName AS [Student],
Books.Name AS [Book], Authors.FirstName & " " & Authors.LastName AS [Author]
FROM
Students,
Books,
S_Cards,
Authors
WHERE
S_Cards.ID_Student = Students.ID
AND S_Cards.ID_Book = Books.ID
AND Books.ID_Author = Authors.ID
ORDER BY Authors.LastName
结果(对不起,它是俄语):
我想不通,为什么我不能像这样 COUNT 和 GROUP BY:
SELECT
Students.FirstName & " " & Students.LastName AS [Student],
Books.Name AS [Book],
COUNT(Authors.FirstName & " " & Authors.LastName) AS [Number of books]
FROM Students, Books, S_Cards, Authors
WHERE
S_Cards.ID_Student = Students.ID
AND S_Cards.ID_Book = Books.ID
AND Books.ID_Author = Authors.ID
GROUP BY 3
我收到一条错误消息,“Authors.FirstName & " " & Authors.LastName' 不是静态函数或组的一部分。
问题:
- 有没有办法在没有 JOIN 的情况下仅通过 GROUP BY、SELECT、UNION 以及如何执行此查询?
- 我的第二个查询有什么问题?