select a.ANAME,b.BNAME from A as a
inner join
(select AID,BNAME from B as t where
not exists(select 1 from B where AId = t.AId and BTime > t.BTime)) as b
on a.AId = b.AId

解决方案 »

  1.   

    select a.ANAME,b.BNAME from A as a join
    (select a1.bname,aid from (select BNAME,max(BTime) btime from B group by bname) a1 join b a2 on a1.bname=a2.bname and a1.btime=a2.btime) as b
    on a.AId = b.AId
      

  2.   

    现在我这里没有sql环境,只能明天验证先谢过楼上
      

  3.   

    create table A(AId int ,AName varchar(100))
    create table B(BId int,BName varchar(100),BTime datetime,AId int)
    --SQL
    select A.AName,TT.BName 
    from A inner join
             (select B.AId,B.BName from (select AId,max(BTime) as BTime from B group by AId) T join B on T.AId=B.AId and T.BTime=B.BTime) as TT 
             on A.AId = TT.AIddrop table A,B
      

  4.   

    select a.aname,b.bname
    from a left join b
    on a.aid=b.aid
    and b.BTime=(select max(BTime) from b where aid=b.aid)
      

  5.   

    select
    a.aname,b.bname
    from 
    a, b, (select aid,max(btime) as btime from b group by aid) b1
    where 
    a.aid=b.aid and b.aid=b1.aid and b.btime=b1.btime
    order by b.bid