如果瞭解您的查詢正確想要attendies其最大的註冊支付等於支付任何與會者最大regitration的列表。
如果因此它可以通過加入幾個子查詢來實現: -
SELECT FirstName, LastName, sub0.MaxRegistrationPaid
FROM tblattendees
INNER JOIN
(
SELECT AttendeeID, MAX(RegistrationPaid) AS MaxRegistrationPaid
FROM tblregistration
GROUP BY AttendeeID
) sub0
ON tblattendees.AttendeeID = sub0.AttendeeID
INNER JOIN
(
SELECT MAX(RegistrationPaid) AS MaxRegistrationPaid
FROM tblregistration
) sub1
ON sub0.MaxRegistrationPaid = sub1.MaxRegistrationPaid
也可以用做HAVING: -
SELECT FirstName, LastName, MAX(RegistrationPaid) AS MaxRegistrationPaid
FROM tblattendees
INNER JOIN tblregistration
ON tblattendees.AttendeeID = tblregistration.AttendeeID
CROSS JOIN
(
SELECT MAX(RegistrationPaid) AS HighestRegistrationPaid
FROM tblregistration
) sub1
GROUP BY FirstName, LastName
HAVING MaxRegistrationPaid >= HighestRegistrationPaid
如果你喜歡,可以考慮下面這個簡單的兩一步一步的行動:1.如果您尚未這樣做,請提供適當的CREATE和INSERT語句(和/或sqlfiddle),以便我們可以更輕鬆地複製問題。 2.如果您尚未這樣做,請提供與步驟1中提供的信息相對應的所需結果集。 – Strawberry