ROW_NUMBER ()
[Syntax] ROW_NUMBER () OVER (partition by COL1 order by COL2)
[Function] indicates to group by COL1 and sort by COL2 within the Group. This value indicates the sequential number after sorting within each group (the continuous and unique in the group)
Row_number () returns "row" information without ranking.
[Parameters]
[Description] Oracle analysis functions
Main function: used to obtain the first or last names.
[Example]
The table content is as follows:
Name | seqno | description
A | 1 | test
A | 2 | test
A | 3 | test
A | 4 | test
B | 1 | test
B | 2 | test
B | 3 | test
B | 4 | test
C | 1 | test
C | 2 | test
C | 3 | test
C | 4 | test
I want to have an SQL statement. The search result is
A | 1 | test
A | 2 | test
B | 1 | test
B | 2 | test
C | 1 | test
C | 2 | test
Implementation:
Select name, seqno, description
From (select name, seqno, description, row_number () over (partition by name order by seqno) id
From table_name) where id <= 3;