查询日期最近的记录,方法比较
--第一种方法
select * from tb a where a.CHANGEDATE=(select max(CHANGEDATE) from tb b where a.CIFSEQ= b.CIFSEQ) order by a.cifseq;
--第二种方法
SELECT a.* FROM tb a
INNER JOIN
(
SELECT CIFSEQ,max(CHANGEDATE) as CHANGEDATE FROM tb
GROUP BY CIFSEQ
) b ON a.CIFSEQ = b.CIFSEQ AND a.CHANGEDATE = b.CHANGEDATE order by a.cifseq;
--第三种方法
select * from tb a where not exists(select 1 from tb b where a.CIFSEQ=b.CIFSEQ and b.CHANGEDATE>a.CHANGEDATE) order by a.cifseq;
select * from tb a where not exists(select 1 from tb b where a.CIFSEQ=b.CIFSEQ and b.CHANGEDATE>a.CHANGEDATE)