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;

,

看完了要说点啥么?


本博客的垃圾评论处理工具最近好像已经更新。但是没有完全配置好。 在垃圾评论处理工具过滤掉你的评论之前,您必须浏览它的管理员页面至少一次(否则可能会混乱)。