A左关联B,取从B表多条记录取一条

select * from a 
left join b on a.ID = b.ID
where not exists (select 1 from b t where t.ID = b.ID and t.TimeEnd > b.TimeEnd)
原文地址:https://www.cnblogs.com/ulex/p/2285652.html