SELECT * FROM (SELECT [PK_EVENT_REPORT_ID] ,[FK_REPORT_FLOW_ID] ,[EVENT_REPORT_KIND] ,[EVENT_REPORT_TYPE] ,[EVENT_REPORT_ORG] ,[EVENT_REPORT_NUMBER] ,DENSE_RANK() OVER(partition by EVENT_REPORT_ORG ORDER BY [EVENT_REPORT_SUMIT_DATE] DESC) AS ROWNUM1 FROM [GCSDB_2].[dbo].[EVENT_REPORTS] ) TT WHERE ROWNUM1<2
第一步 分组排序,加上编号,第二步删选第几名
oracle类似,只不过加函数不同
select * from (
select t.*,row_number() over(partition by t.subject_no order by t.score desc) pm from score t) where pm<4;
oracle是用row_number 来加编号的