尝试这个:
SELECT L.Loanno, L.Balanceamount, L.DueDate
FROM dbo.Loan L
INNER JOIN
(
SELECT Loanno, MAX(Balancemount) as MaxBalance FROM dbo.Loan
GROUP BY LoanNo
) SUB ON L.Loanno = SUB.Loanno AND L.Balanceamount = SUB.MaxBalance
子查询返回Maximum balance
每个 LoanNo(无论日期如何)当连接回您的原始表时,您会留下 LoanNo、最大余额和到期日期。
好的,刚刚在 MS Access 中测试了下面的查询,它工作得很好,Table1
用您的实际表名替换:
SELECT T.LoanNo, T.DueDate, T.BalanceAmount
FROM Table1 As T
INNER JOIN (
SELECT T.Loanno, Max([T.Balanceamount]) AS MaxBalance
FROM Table1 as T
GROUP BY T.Loanno) SUB ON T.LoanNo = SUB.LoanNo AND T.BalanceAmount = SUB.MaxBalance