加个分组编号就可以,分组按照a.ZT分的可根据需要更改,然后按照ID01降序排列,取编号为1的就可以啦。
select c.* from
(SELECT a.ID,a.TYPE,a.PHE,a.COMPANY,a.REPORT_TYPE,a.PROPOS_DATE,a.PROPOSER,a.REPORT_DATE,
a.TIME,a.CONT_MEASURE,a.ROOT_CAUSE,a.ZT,a.GZ,PRIORITIES,a.APPEAR,a.STEP,a.ID01,a.HEBING,
case when a.HEBING is null then TO_CHAR(a.id01) else SUBSTR(a.HEBING,1,INSTR(a.HEBING,'''')-1) end as 前面,
trim(replace(substr(replace(a.HEBING,',',lpad(' ',40,' ')) ,15,35),chr(39),'')) as 中间,
trim(replace(substr(replace(a.HEBING,',',lpad(' ',40,' ')) ,70,35),chr(39),'')) as 最后,
b.xcbgrq,
(@i := case when @key_i=a.ZT then @i+1 else 1 end) as sort_num,
(@key_i:=a.ZT) as tmp
from QRQC_TRACK_REPORT a
left join (select ID01, max(propos_date) as xcbgrq from QRQC_TRACK_REPORT group by ID01) b on a.ID01=b.ID01,
(SELECT @i := 0,@key_i:='') b
ORDER BY a.ZT,a.ID01 desc) c
where c.sort_num=1;