关键字 ROW_NUMBER() OVER(PARTITION BY 分组字段 ORDER BY 排序字段) RN
按照分组字段进行排序并标编号
ROW_NUMBER() OVER(PARTITION BY 分组字段 ORDER BY 排序字段) RN
语法
ROW_NUMBER() OVER(PARTITION BY XMJL_UID ORDER BY XMCREATETIME) RN
实例
SELECT XMJL_UID,XMJL,XMCREATETIME,ROW_NUMBER() OVER(PARTITION BY XMJL_UID ORDER BY XMCREATETIME) RN FROM SHZT_XMGL WHERE XMSTATUS='进行中' ORDER BY XMCREATETIME
SELECT * FROM ( SELECT XMJL_UID,XMJL,XMCREATETIME,ROW_NUMBER() OVER(PARTITION BY XMJL_UID ORDER BY XMCREATETIME) RN FROM G_INFOS WHERE B.XMSTATUS='进行中' ORDER BY XMCREATETIME ) WHERE RN=