需求: 按照表的字段分组,然后每组取10条结果,返回即可
sql 如下:
SELECT
*
FROM (SELECT chk_id,feature_id,task_id, ROW_NUMBER () OVER (PARTITION BY chk_id ORDER BY chk_id) AS row_num
FROM ics_check_report
WHERE task_id = '10069'
) as a
WHERE a.row_num < 11
展示查询结果:
sql解释语法如下:
row_number() over( [partition by col1] order by col2[desc])
partition by chk_id :要分组的字段
order by chk_id : 要排序字段
row_number () :为返回的记录定义各行编号