日期:2014-05-17 浏览次数:20903 次
with t(userid,money,dttime,year) as
(
select 1,200,to_date('2012-03-04','yyyy-mm-dd'),2012 from dual
union all select 1,200,to_date('2012-05-04','yyyy-mm-dd'),2012 from dual
union all select 2,200,to_date('2012-05-04','yyyy-mm-dd'),2012 from dual
union all select 2,200,to_date('2012-03-04','yyyy-mm-dd'),2012 from dual
)
select * from t where dttime=(select max(dttime) from t t1 where t.userid=t1.userid and t.year=2012);
/*
USERID MONEY DTTIME YEAR
---------- ---------- -------------- ----------
1 200 04-5月 -12 2012
2 200 04-5月 -12 2012
*/