17,377
社区成员
发帖
与我相关
我的任务
分享
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