select*from target_table a
innerjoin tmp_table b
on a.key_name = b.key_name and a.stat_date = b.last_date
单条SQL实现,适合数据量比较小的情况
1
select*from target_table a
where stat_date =(selectmax(stat_date)from target_table b
where a.key_nam=b.key_nam);
2
select a.*from target_table a
wherenotexists(select1from target_table b
where b.key_name=a.key_name and b.stat_date>a.stat_date)
3
select a.*from target_table a
innerjoin(select key_name,max(stat_date)as maxstat_date
from target_table
groupby key_name) b
on a.key_name=b.key_name and a.stat_date=b.maxstat_date