表数据如: 以CODE 作为版本分组字段,对创建时间进行按最新排序
ID NAME CODE CREATE_TIME
1ffg abc 001 2014-01-01
1gffd kabc 001 2014-01-02
1hfd labc 001 2014-01-03
1ghd abc 002 2014-01-01
1fhd kabc 002 2014-01-06
1ffd labc 002 2014-01-03
SELECT * FROM ( select ID,NAME,CODE,CREATE_TIME ROW_NUMBER() OVER(PARTITION BY CODE ORDER BY CREATE_TIME DESC) AS RN FROM sys_oa_form T) WHERE RN = 1 and id!='0'
结果如下
1hfd labc 001 2014-01-03
1fhd kabc 002 2014-01-06