三个表a   b  c 
a  id  name
b  id  time
c  id  rscount求出每个ID对应的B表中的最新时间NAME RSCOUNT

解决方案 »

  1.   

    select a.id, a.name,b.time from (select id ,max(time) as time  from b)b left join a
    on b.id = a.id
    join c on b.id = c.id 
      

  2.   

    select a.id, a.name,b.time ,c.rscount
    from (select id ,max(time) as time  from b)b 
    left join a
    on b.id = a.id
    join c 
    on b.id = c.id
      

  3.   

    --創建測試環境
    Create Table a
    (ida varchar(11),
    nam varchar(31))
    GO
    Insert a Select         '1',                      '1'
    Union All Select        '2',                      '1'GOCreate Table b
    (idb varchar(11),
     tim datetime)
    GO
    Insert b Select         '1',                          '2007-07-01'
    Union All Select        '1',                      '2007-07-02'
    Union All Select        '1',                      '2007-08-03'
    Union All Select        '2',                      '2007-03-03'
    Union All Select        '2',                      '2007-03-04'GO
    Create Table c
    (idc varchar(11),
     rscount float)
    GO
    Insert c Select         '1',                      22
    Union All Select        '2',                      22GOselect ida id ,nam name
    ,time =  (select top 1 tim from b where idb = ida order by tim desc)
    ,rscount 
    from a full  join c on idc = ida