select max(data),id from tabel group by id

解决方案 »

  1.   

    忘记说了
    表B的结构可鞥那是
    id data1  data2  data2
    1  100     101    102
    1  200     202    203
    2 300      302     303
    4  400    102   403得到的结果
    1 100 101 102
    2  300 302 303
    或者
    1 200 202 203
    2  300 302 303
      

  2.   

    select a.id, max(b.data) as data--或者 min(b.data)
    from 表A a join 表B b on a.id = b.id
    group by a.id
      

  3.   

    select a.id,data=min(b.data)
    from ta a,tb b where a.id=b.id group by a.id
    --or
    select a.id,data=max(b.data)
    from ta a,tb b where a.id=b.id group by a.id
      

  4.   

    select b.* from ta a,tb b where a.id=b.id and 
    not exists(select 1 from tb where id=b.id and data1<b.data1)
    --or
    select b.* from ta a,tb b where a.id=b.id and 
    not exists(select 1 from tb where id=b.id and data1>b.data1)