oracle - 如何用最新记录消除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'
解决方案
您正在按 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 的最新记录
推荐阅读
- git - 远程删除文件夹但不是本地git
- excel - 如果满足某些条件并将结果输入另一个工作簿,则计算行数
- c# - C# PInvoke 我无法使用 CreateFile 打开卷
- python - 运行从不同位置导入另一个 python 脚本的 Python 脚本
- https - Https重定向在cakephp 4中不起作用
- c++ - 用 Eigen 找到最近的正定矩阵
- amazon-s3 - AWS 预签名 URL 上传速度慢
- asp.net-core - DbContext 的子类:一个整体还是每个模型一个?
- git - 带有忽略空间的 git diff --name-only 似乎已损坏
- macos - Mac App Store 之外的分发:请删除前缀“开发者 ID 应用程序:”