表1
 a    b    c
 e1   1    s
 e1   2    t
 e1   3    j1
 e2   1    s
 e2   1    s
 e2   2    t
 e2   3    j
 e2   4    k
得到 
a    b    c
e1   3    j
e2   4    k然后有个表5
aa   bb   cc  dd
e1   2     j  2
e1   2     e  23
e1   2     s  213
e2   1     k  223
e2   2     j  232
e2   2     d   23想得到 
aa   bb    cc   dd
e1   2     j    2
e2   1     k  223
也就表1中b最大的对引的,到表5中比较
得到我想得到的东西!希望子陌大哥来帮忙

解决方案 »

  1.   

    表起到了什么作用:select * from 表5 a where not exists(select 1 from 表5 where aa=a.aa and bb>a.bb)
      

  2.   

    SELECT CC.* FROM
    (SELECT a, c FROM 表1 AS AA
    WHERE NOT EXISTS (SELECT * FROM 表1 WERE AA.a = a AND AA.b > b)) AS BB
    INNER JOIN
    表5 AS CC
    ON BB.a = CC.aa AND BB.c = CC.cc
      

  3.   

    select n.* from (
    select * from 表1 a where not exists(select 1 from 表1 where a=a.a and b>a.b)
    ) m
    inner join 表5 n 
    on m.a=n.aa and m.c=n.cc
      

  4.   

    好不容易才看清楚,,LZ以后还是少用a,b,c,aa,bb,cc之类的来做表的名称,表多了,都是这样的,会把眼看花的...呵呵!
      

  5.   

    select t2.a1 ,
           t2.bb  ,
           t2.cc  ,
           t2.dd(
    select  tt.a as a1,
            tt.b as a2,
            t.c  as a3
    (
    select a ,
          max(b) as b
    from t1 
    ) tt 
    inner join t
    on t.a = tt.a
    and t.b = tt.b
    ) tt1
    inner join t2
    on tt1.a = t2.aa
    and tt1.a3 = t.cc