Reputation: 13
I would like to group data on some column called CustID and select their first or the last mortgage even if the mortgages were originated on the same date. How do you do that in Netezza? In MS Access I normally use the First or Last aggregation functions for that.
Data comes like this:
CustID mortgageID pass_dt
101 090234W 1-23-1989
101 103120X 5-20-2020
101 103121V 5-20-2020
So here I want either the second or the third record but not both when as extra criterium pass_dt = 5-20-2020.
Thanks very much!
Upvotes: 1
Views: 53
Reputation: 1269673
If you want the entire record, use window functions:
select t.*
from (select t.*, row_number() over (partition by custid order by pass_dt desc) as seqnum
from t
) t
where seqnum = 1
Upvotes: 1