取重复记录中时间最新的一条记录Oracle sql语句

WITH t1 AS ( SELECT YLPLID,MAX(SBSJ) SBSJ FROM YLPLCG where YLPLID in(select YLPLID from CYQYCPYLPLGX where CPID='659DE0BC42544B74B660E37E665F437C') group by YLPLID )   SELECT t.YLPLMC,case when t.YLPLLX =1 then '原料' when t.YLPLLX = 2 then '配料' end YLPLLX , t.GYSID,t.GYSMC,t.JYHGBGDTPID FROM  YLPLCG t INNER JOIN t1 ON t.YLPLID = t1.YLPLID AND to_char(t.SBSJ, 'yyyy-MM-dd HH24:mm:ss')= to_char(t1.SBSJ, 'yyyy-MM-dd HH24:mm:ss')

 

posted on 2017-07-05 00:00  wuzx-blog  阅读(668)  评论(0编辑  收藏  举报