日期:2014-05-17 浏览次数:20791 次
with t1 as ( select 1 id,'xh001' xh,'张三' name from dual union all select 2 id,'xh002' xh,'李四' name from dual ), t2 as ( select 1 id,'xh001' xh,date'2012-09-21' time,'192.168.100.100' ip from dual union all select 2 id,'xh001' xh,date'2012-09-23' time,'192.168.100.101' ip from dual union all select 3 id,'xh001' xh,date'2012-09-28' time,'192.168.100.102' ip from dual union all select 4 id,'xh002' xh,date'2012-09-22' time,'192.168.100.103' ip from dual union all select 5 id,'xh002' xh,date'2012-09-28' time,'192.168.100.104' ip from dual union all select 6 id,'xh002' xh,date'2012-09-24' time,'192.168.100.105' ip from dual ) select c.xh,c.name,d.time,d.ip from t1 c, ( select a.* from t2 a,(select xh,max(time) time from t2 group by xh) b where a.xh = b.xh and a.time = b.time ) d where c.xh = d.xh xh name time ip --------------------------- 1 xh001 张三 2012/9/28 192.168.100.102 2 xh002 李四 2012/9/28 192.168.100.104