比如有下面的表:
a    b     c
1    1     p
1    2     u
1    3     y
2    1     q
2    2     w
2    3     e
要找出 a各组记录中 b值最大的记录对应的C值
即找出 1 3 y
      2 3 e菜鸟紧急求助,谢谢赐教

解决方案 »

  1.   

    SELECT * from 表名 where a=(select max(a)from 表名) and a=(select max(b)from 表名) and c=a=(select max(c)from 表名)
      

  2.   

    select a.a, a.b, a.c
      from (select x.*, row_number() over(partition by x.a order by b desc) rn
              from tablename x) a
     where rn = 1
      

  3.   

    SQL> select * from c1;         A          B C
    ---------- ---------- ----------
             1          1 p
             1          2 u
             1          3 y
             2          1 q
             2          2 w
             2          3 e6 rows selectedSQL> 
    SQL> select a.a, a.b, a.c
      2    from (select x.*, row_number() over(partition by x.a order by b desc) rn
      3            from c1 x) a
      4   where rn = 1
      5  ;         A          B C
    ---------- ---------- ----------
             1          3 y
             2          3 eSQ