日期:2014-05-17 浏览次数:20928 次
SELECT username,MAX(login_time) FROM user_login GROUP BY username
with user_login as(
select 'A' username,to_date('2012-9-1','yyyy-mm-dd') login_time from dual
union all
select 'A',to_date('2012-9-3','yyyy-mm-dd') from dual
union all
select 'A',to_date('2012-9-4','yyyy-mm-dd') from dual
union all
select 'B',to_date('2012-9-3','yyyy-mm-dd') from dual
union all
select 'A',to_date('2012-9-7','yyyy-mm-dd') from dual
union all
select 'C',to_date('2012-9-6','yyyy-mm-dd') from dual
union all
select 'D',to_date('2012-9-8','yyyy-mm-dd') from dual
)select username,max(login_time) from user_login group by username;
USERNAME MAX(LOGIN_TIME)
-------- ---------------
D 2012/9/8
A 2012/9/7
B 2012/9/3
C 2012/9/6