日期:2014-05-18 浏览次数:20506 次
SELECT * FROM A,B WHERE B.DATETIME=(SELECT MAX(DATETIME) WHERE A.AID=B.BID) AND A.AID=B.BID
SELECT * FROM A left join (select * from B t where not exists(select 1 from B where BID=t.BID and [DATETIME ]>t.DATETIME )) n on A.AID=n.BID
------解决方案--------------------
select m.* , n.* from a m left join b n on m.AID = n.BID and n.DATETIME = (select max(DATETIME) from b where bid = n.bid) select m.* , n.* from a m left join b n on m.AID = n.BID and not exists (select 1 from b where bid = n.bid and DATETIME > n.DATETIME)
------解决方案--------------------
select *
from a
left join b
on a.AID = b.BID
and b.DATETIME=(SELECT distinct MAX(DATETIME) WHERE a.AID=b.BID)