这是一张记录用户A 给b 和 c 通话的记录
time是通话日期如何从表中查出A所打的不同用户中的通话日期距离当前最近的记录 
上表 期望结果:
A C 2012.5.22
A B 2012.3.23

解决方案 »

  1.   

    with t (c_id, p_id, time) as (
              select 'A', 'B', to_date('2012.03.12', 'yyyy.mm.dd') from dual
    union all select 'A', 'B', to_date('2012.03.23', 'yyyy.mm.dd') from dual
    union all select 'A', 'C', to_date('2012.04.12', 'yyyy.mm.dd') from dual
    union all select 'A', 'C', to_date('2012.05.22', 'yyyy.mm.dd') from dual
    )
    select c_id, p_id, max(time) from t group by c_id, p_id;
      

  2.   


    select * from 你的表 t1 where t1.time=(select max(time) from 你的表 t2 where t1.c_id=t2.c_id and t1.p_id=t2.p_id);
      

  3.   

    select * from (
     select distinct  l.p_id, l.C_ID, max(l.time) over(partition by l.p_id order by l.time desc ) as time 
     from call_log l ) order by time desc一楼和二楼 都对..........
      

  4.   

    with t (c_id, p_id, time) as (
              select 'A', 'B', to_date('2012.03.12', 'yyyy.mm.dd') from dual
    union all select 'A', 'B', to_date('2012.03.23', 'yyyy.mm.dd') from dual
    union all select 'A', 'C', to_date('2012.04.12', 'yyyy.mm.dd') from dual
    union all select 'A', 'C', to_date('2012.05.22', 'yyyy.mm.dd') from dual
    )
    select c_id, p_id, max(time) from t group by c_id, p_id;
      

  5.   

    select C_id,P_id,time
    order by time desc
    我不知道是不是理解错了,我感觉楼主的需求只是要按日期从最近到最远。
      

  6.   


    好吧,我错了,漏看了几个楼主的需求的里的字,现在重新下下!
    新结果:select C,P,max(Time) from table_1 group by C,P
      

  7.   

    max 好像 就解决了 lz的问题?