解决方案 »

  1.   

    C字段是否添加了索引,
    尝试吧select A,max(c) from table  group by A 单独建一张临时表,子查询实在影响效能,然后再和主表关联!
      

  2.   

    select a.* from table a,(select A, max(c) over(order by c) maxc from table )b where  and b.mac=a.C;
    select a.* from table a where  a.C = (Select Max(c)
                                   From table b
                                  Where a.A = b.A)
      

  3.   

    WITH c_test AS(
         SELECT '张三' A,TRUNC(dbms_random.value(10,100)) D,TRUNC(dbms_random.value(10,100)) B,20130411 C FROM dual 
         UNION
         SELECT '张三' A,TRUNC(dbms_random.value(10,100)) D,TRUNC(dbms_random.value(10,100)) B,20130511 C FROM dual 
         UNION
         SELECT '张三' A,TRUNC(dbms_random.value(10,100)) D,TRUNC(dbms_random.value(10,100)) B,20130311 C FROM dual 
         UNION
         SELECT '李四' A,TRUNC(dbms_random.value(10,100)) D,TRUNC(dbms_random.value(10,100)) B,20130611 C FROM dual 
         UNION
         SELECT '李四' A,TRUNC(dbms_random.value(10,100)) D,TRUNC(dbms_random.value(10,100)) B,20130311 C FROM dual 
         UNION
         SELECT '李四' A,TRUNC(dbms_random.value(10,100)) D,TRUNC(dbms_random.value(10,100)) B,20130411 C FROM dual 
         UNION
         SELECT '王五' A,TRUNC(dbms_random.value(10,100)) D,TRUNC(dbms_random.value(10,100)) B,20130311 C FROM dual 
         UNION
         SELECT '王五' A,TRUNC(dbms_random.value(10,100)) D,TRUNC(dbms_random.value(10,100)) B,20140211 C FROM dual 
    )
    SELECT *
      FROM c_test t
     WHERE EXISTS (SELECT 1
                     FROM (SELECT t.a,MAX(t.c) c
                             FROM c_test t
                            GROUP BY t.a) b
                    WHERE b.a = t.a
                      AND t.c = b.c); 
      

  4.   

    select *
    from a t
    where not exists(select 1 from a where a=t.a and c>t.c);
      

  5.   

    select a,d,b,max(c) from table group by a,d,b
      

  6.   

    5楼正解,
    7楼结果应该是不正确的
    例:按照ADB分组
    结果中 
    张三 65 73
    张三 66 74
    张三 69 77
    在结果中应该都会出现,而按楼主的要求,应该只要最新的一条
      

  7.   

    你试试这样行不行
    select a,d,b,max(c) from table group by a
      

  8.   

    分析函数
    row_number() over(parititon by ..... order by .... desc)
      

  9.   

    如12楼所说,分析函数。
    select * from
    (select  a.*,row_number() over(partition by a.a order by a.c desc) rn)
    where rn=1;
      

  10.   

    select *
    from q t
    where not exists(select 1 from q where A=t.A and C>t.C); 
      

  11.   

    WITH c_test AS(     
    SELECT '张三' A,TRUNC(dbms_random.value(10,100)) D,TRUNC(dbms_random.value(10,100)) B,20130411 C FROM dual      
    UNION     
    SELECT '张三' A,TRUNC(dbms_random.value(10,100)) D,TRUNC(dbms_random.value(10,100)) B,20130511 C FROM dual      
    UNION     
    SELECT '张三' A,TRUNC(dbms_random.value(10,100)) D,TRUNC(dbms_random.value(10,100)) B,20130311 C FROM dual      
    UNION     
    SELECT '李四' A,TRUNC(dbms_random.value(10,100)) D,TRUNC(dbms_random.value(10,100)) B,20130611 C FROM dual      
    UNION     
    SELECT '李四' A,TRUNC(dbms_random.value(10,100)) D,TRUNC(dbms_random.value(10,100)) B,20130311 C FROM dual      
    UNION     
    SELECT '李四' A,TRUNC(dbms_random.value(10,100)) D,TRUNC(dbms_random.value(10,100)) B,20130411 C FROM dual      
    UNION     
    SELECT '王五' A,TRUNC(dbms_random.value(10,100)) D,TRUNC(dbms_random.value(10,100)) B,20130311 C FROM dual      
    UNION     
    SELECT '王五' A,TRUNC(dbms_random.value(10,100)) D,TRUNC(dbms_random.value(10,100)) B,20140211 C FROM dual 
    )
    select a.* from c_test a,
    (select s.a name,max(c) maxtime from c_test s group by s.a) b 
    where a.A=b.name and a.C=b.maxtime;