首页 > 解决方案 > 如何用最新记录消除oracle中的价值

问题描述

    i will get latest record by timestamp but it is not filter desired 

这里的输出是我试图获取最新记录的代码,但它对我不起作用。我会附上一张图片以便更好地理解。你能找出问题所在 在此处输入图像描述

    select *
    from (select
       id,NPCI_REFMSGID,TO_CHAR (created_date, 'dd.mm.rrrr hh24:mi:ss.ff3')AS created_Date, 
      rank() over (partition by ID order by TO_CHAR (created_date, 'dd.mm.rrrr hh24:mi:ss.ff3') desc) r
      from emnd_tblemandate_mst
      --where end_enrollment_date is null
    )
    where r = 1 AND NPCI_REFMSGID='1ea345bc63644b53a88076040ef979e3'

标签: oracle

解决方案


您正在按 ID 进行分区,因此您可以在结果中获得所有行。认为应该是

select *
from (select id 
           , NPCI_REFMSGID
           , TO_CHAR (created_date, 'dd.mm.rrrr hh24:mi:ss.ff3')AS created_Date
           , rank() over (partition by NPCI_REFMSGID order by created_date desc) r
      from   emnd_tblemandate_mst
)
where r = 1 
AND   NPCI_REFMSGID = '1ea345bc63644b53a88076040ef979e3'

然后您只获得特定 NPCI_REFMSGID 的最新记录


推荐阅读