Oracle我还未入门,写一个SQL Server中能通过的供参考:
select * from tablename  TA inner join (slect a,b,max(d) as md from tablename group by a,b) as TB on TA.a=TB.a and TA.b=TB.b and TA.d=TB.md

解决方案 »

  1.   

    select a,b,max(c),d from tbname,(select a,b,max(d) from tbname group by a,b) t
    where tbname.a=t.a and tbname.b=t.b and tbname.d=tb.d
    group by a,b,d;
      

  2.   

    select tab1.a,tab1.b,min(tab1.c),tab1.d from yourtable tab1,
    ( select a,b,max(d) max_d from yourtable group by a,b) tab2
    where tab1.a=tab2.a and tab1.b=tab2.b and tab1.d=tab2.max_d
    group by tab1.a,tab1.b,tab1.d
      

  3.   

    谢谢bdwg(随便),
    我还没有试过你上面的SQL语句,不过我对它有一点疑问,
    select * from tablename  TA是选择了全部,
    那么就应该满足“D相同时随机取一个“的条件
      

  4.   

    对不起,这里是欠考虑,应该加上DISTINCT谓词:select distinct * from ...
    -------------------------------------------------------------------------
    我的MSN: [email protected]。欢迎加我。我想从头学Oracle,需要大家的支持。
      

  5.   

    select a,b,min(c),d
    (select a,b,c,d,rank(d) over(partition by a,b order by d desc) rk from tab1)
    where rk=1 group by a,b,d
      

  6.   

    select a,b,c,max(d) from tablename group by a,b呵呵,44
      

  7.   

    SELECT a,b,MAX(c)c,d FROM tablename WHERE  tablename.d IN (SELECT  max(d) FROM tablename WHERE a<>b   GROUP BY tablename.a) GROUP BY a,b,d
      

  8.   

    我刚才没考虑到c
    应该这样:
    select test1.a,test1.b,test1.c,test1.d
    from test1,(select a,b,max(d) as md from test1 group by a,b) as test2
    where  (test1.a=test2.a)
    and (test1.b=test2.b)
    and (test1.d=test2.md)
      

  9.   

    我的思路是这样的,select a,b,max(d) as md from test1 group by a,b得到的是你要的表,但是没有C字段,因为这是group by不支持的。
    但是没关系,我们就查询表中test1.a=test2.a;test1.b=test2.b;test1.d=test2.md,就可以得到你的结果了,我已经测试过正确无误。
      

  10.   

    非常感谢各位!
    看了几为给出的解决方法之后,
    我考虑到在本应用中d的取值范围是1—9,
    所以我这样做:
    select a,b,max(TO_CHAR(d)||c) as dc from tablename group by a,b
    取到结果之后再把dc拆开来用。