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;
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);
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一楼和二楼 都对..........
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;
select C_id,P_id,time order by time desc 我不知道是不是理解错了,我感觉楼主的需求只是要按日期从最近到最远。
好吧,我错了,漏看了几个楼主的需求的里的字,现在重新下下! 新结果:select C,P,max(Time) from table_1 group by C,P
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;
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);
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一楼和二楼 都对..........
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;
order by time desc
我不知道是不是理解错了,我感觉楼主的需求只是要按日期从最近到最远。
好吧,我错了,漏看了几个楼主的需求的里的字,现在重新下下!
新结果:select C,P,max(Time) from table_1 group by C,P