select出重复的数据,有没办法只保留最近的一条记录
select name, result , changedate from t
取出来的name可能有相同的,这种情况下有没办法根据changedate这条数据的插入时间,只取出最近的一条记录呢?
[解决办法]
select name,result,changedate from t a where not exists (
select name,result,changedate from t b where a.name=b.name and a.changedate<b.changedate)
[解决办法]
select name,result,changedate
from t
where (name,changedate) in (select name,max(changedate) from t group by name);
select *
from (select name,
result,
changedate row_number() over(partition by name order by changedate desc) as_level
from t) temp
where temp.as_level = 1