What I am trying to do seems so simple, I am not sure why I am having trouble. I am trying to get the Highest transaction amount for each of our customers, however many times they give the same amount every month so in that case I need to find their single highest transaction with the latest transaction date. I have the following sql which pulls the customers highest transactions, but if there are multiple, how do I say only give me the latest transaction date?
SELECT dt3.donorid, dt3.trandate, dt3.tranamount, dt3.transourcecode
FROM (SELECT DT.trandate, DT.tranamount, DT.donorid, DT.transourcecode
FROM donortrans dt, donor d
WHERE tranamount = (
Select Top 1 max(tranamount)
From donorTrans dt2
where dt2.tranamount>0 and
dt2.donorid =dt.donorid)
and dt.donorid=d.Donorid
) as DT3, donor d
WHERE DT3.DonorID = d.Donorid and d.donorid=10058
ORDER BY DT3.Donorid
Thansk so much for your help!
SELECT dt3.donorid, dt3.trandate, dt3.tranamount, dt3.transourcecode
FROM (SELECT DT.trandate, DT.tranamount, DT.donorid, DT.transourcecode
FROM donortrans dt, donor d
WHERE tranamount = (
Select Top 1 max(tranamount)
From donorTrans dt2
where dt2.tranamount>0 and
dt2.donorid =dt.donorid)
and dt.donorid=d.Donorid
) as DT3, donor d
WHERE DT3.DonorID = d.Donorid and d.donorid=10058
ORDER BY DT3.Donorid
Thansk so much for your help!