数据库去重复数据最新或最小记录.

取最小记录

没有比它更小的记录,那么就是最小记录

select v1.id,v2.id from certification_version v1 left join certification_version v2 on v1.certification_id = v2.certification_id
and v1.deleted = 'f'
and v2.created_time < v1.created_time
where 1=1
--and v1.id ='d0196569-393d-4bb1-a843-7b058efca61d'
and v2.id is null
and v1.certification_id = 'c1bb788b-cce3-4377-baae-53e4b4f589d8'

取最大记录

没有比它更新的记录,那么它就是最新记录

select v1.id,v2.id from certification_version v1 left join certification_version v2 on v1.certification_id = v2.certification_id
and v1.deleted = 'f'
and v1.created_time < v2.created_time
where 1=1
--and v1.id ='d0196569-393d-4bb1-a843-7b058efca61d'
and v2.id is null
and v1.certification_id = 'c1bb788b-cce3-4377-baae-53e4b4f589d8'