一、通過分組排序,加上一個序號列,獲取最新記錄(僅供參考)
select count(1) from ( select NCPYPCJSJ,dense_rank() over(order by NCPYPCJSJ desc) as OrderID from NCPYPJCXXB inner join TRJCDXXB on NCPYPJCXXB.DWBH=TRJCDXXB.DWBH --where QSDWDM=CODE and QSDWMC=NAME and NCPYPJCXXB.NCPCBCD='1' )N where OrderID=1
二、摘自:https://blog.csdn.net/stephenhendery/article/details/79236671
-- 方法1 select a.* from table1 a where not exists(select 1 from table1 b where b.name=a.name and b.gdtime>a.gdtime) -- 方法2 select a.* from table1 a inner join (select name, max(gdtime) 'maxgdtime' from table1 group by name) b on a.name=b.name and a.gdtime=b.maxgdtime