该函数可以将表中信息进行分组,组内排序并列出序号。
eg:
将student表按照abc三个字段分组,组内按照c字段升序。
select *, row_number() over(partition by A, B, C order by C asc) rank
from student;
eg:
将student表按照abc三个字段分组,每组取C字段最小的记录。
select * from (
select *, row_number() over(partition by A, B, C order by C asc) rank
from student) o where o.rank = 1;