select * from table1 as a
left join table2 as b on a.ID = b.ID
where exists
(
select table1 from
(
select ID ,max(DateTime) as Time
from table1 group by ID
)as n where n.ID= b.ID and n.Time= a.DateTime
)
转载于:https://www.cnblogs.com/zhongyinglei/p/4807578.html