这是我的数据
Id Name Amt 1 ABC 20 2 XYZ 30 3 ABC 25 4 PQR 50 5 XYZ 75 6 PQR 40
我希望每个特定名称的最后一条记录如:
3 ABC 25 5 XYZ 75 6 PQR 40
我尝试过分组,但我错过了一些东西.
SELECT PatientID, Balance, PReceiptNo FROM tblPayment GROUP BY PatientID, Balance, PReceiptNo
Patrick Kost.. 6
这样的事情应该有效:
SELECT p1.* FROM tblPayment p1 LEFT JOIN tblPayment p2 ON p1.Name = p2.Name AND p1.Id < p2.Id WHERE p2.Id IS NULL;
看到这个SQLFiddle
这样的事情应该有效:
SELECT p1.* FROM tblPayment p1 LEFT JOIN tblPayment p2 ON p1.Name = p2.Name AND p1.Id < p2.Id WHERE p2.Id IS NULL;
看到这个SQLFiddle