有一个这样的表(a,b,c)现在我如果想做这样的操作,先按a分组找出b的最大值,再在结果中找出c的最大值的那一个记录。这样的SQL语言要怎么写?

解决方案 »

  1.   

    是要这样子的吗?with t as (
    select 1 as a, 2 as b, 3 as c from dual
    union all
    select 1,2,4 from dual
    union all
    select 1,2,8 from dual
    union all
    select 2,3,2 from dual
    union all
    select 2,3,8 from dual
    union all
    select 3,3,9 from dual
    union all
    select 3,3,8 from dual
    )
    select a ,max(b),max(c) from t
    group by awith t as (
    select 1 as a, 2 as b, 3 as c from dual
    union all
    select 1,2,4 from dual
    union all
    select 1,2,8 from dual
    union all
    select 2,3,2 from dual
    union all
    select 2,3,8 from dual
    union all
    select 3,3,9 from dual
    union all
    select 3,3,8 from dual
    )
    select a ,max(b),max(c) from t
    group by aA                      MAX(B)                 MAX(C)                 
    ---------------------- ---------------------- ---------------------- 
    1                      2                      8                      
    2                      3                      8                      
    3                      3                      9                      
      

  2.   

    ls上的,你说这样行不行?
    select * from table where c in(select max(c) from (select * from table where b in(select max(b) from table group by a))as table2 group by a);
      

  3.   

    select a ,max(b),max(c) from t
    group by a