Access SQL查询中的Count函数

时间:2013-11-12 19:11:44

标签: mysql ms-access

按名称列出客人,并在每家酒店预订客房的次数。按照从最常见到最不常见的客人的顺序排列列表。

我一直在为Firstname和LastName获取聚合函数

到目前为止我有这段代码

SELECT FirstName, LastName, Count(ResNum) AS TotalReservations
FROM RESERVATION, GUEST
Where GUEST.GuestNo = RESERVATION.GuestNo
ORDER BY RESERVATION.GuestNo

以下是RelationShip表的链接

View Relationship Table < --- LINK

2 个答案:

答案 0 :(得分:1)

试试这个:

SELECT FirstName, LastName, Count(ResNum) AS TotalReservations
FROM RESERVATION
INNER JOIN GUEST ON GUEST.GuestNo = RESERVATION.GuestNo
GROUP BY FirstName, LastName
ORDER BY COUNT(ResNum) DESC

答案 1 :(得分:0)

SELECT g.FirstName, g.LastName, Count(r.ResNum) AS TotalReservations
FROM RESERVATION AS r
INNER JOIN GUEST AS g ON g.GuestNo = r.GuestNo
GROUP BY g.FirstName, g.LastName
ORDER BY Count(r.ResNum) DESC