库中有四条数据,是两条数据分成了两个版本,如何动态取最大版本的两条数据
select * from table a
left join (select id,max(版本)as max_bb from table group by id) b
on a.id = b.id and a.版本 = b.max_bb
如果支持开窗函数得话 可以这么写
select * from(
select 其他字段,版本,row_number()over(partition by 分组字段 order by 版本 desc ) as rn
) t
where rn=1