语句如下:

select *  
  from (select t.*,  
               (Row_number() over(partition by 分组字段 order by 排序字段)) rn  
          from 表名字 t)  
 where rn < 6;

示例:

select *  
  from (select t.*,  
               (Row_number() over(partition by t.type order by t.id)) rn  
          from tbl_requisition t)  
 where rn < 6;

意思是:根据 tbl_requisition 表中的 type 类型进行分组,取前 5 条,且这 5 条数据是根据 id 排序的

来个截图(查找结果)

已有0条评论