This question is different from Get top 1 row of each group. In my question, each group is consists of two columns (col1
, col2
), while in his question each group is consists of only one column (col1
). I also tried to modify the answer in his question but failed.
Example:
Suppose n = 1
Input:
col1 col2 x Amt
A B x1 100
A B x2 200
C D x3 400
C D x4 500
...more data ...
Output:
col1 col2 x Amt
A B x2 200
C D x4 500
...more data ...
What I tried ...select *, row_numne() over ( partition by (col1, col2) order by ...