row_number() over (partition by col1 order by col2) 表示根据col1分组,在分组内部根据 col2排序 而这个值就表示每组内部排序后的顺序编号(组内连续的唯一的)
表内容如下: 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
我想有一个sql语句,搜索的结果是 A | 1 | test A | 2 | test B | 1 | test B | 2 | test C | 1 | test C | 2 | test 实现: 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;