-- Oracle: first/last functions
with s (user_ID, grp, Login_Date) as (
select 'Mulan', 'Flower' , to_date('4/4/2017' , 'mm/dd/yyyy') from dual union all
select 'Mulan', 'Badminton', to_date('11/20/2015', 'mm/dd/yyyy') from dual union all
select 'Mulan', 'Flower' , to_date('11/20/2015', 'mm/dd/yyyy') from dual)
select
user_id,
max(grp) keep (dense_rank last order by login_date) as grp,
max(login_date) as log_date
from s
group by user_id;
USER_ GRP LOG_DATE
----- --------- -------------------
Mulan Flower 2017-04-04 00:00:00
Ответ на дополнительный вопрос:
with s (user_ID, grp, Login_Date) as (
select 'Mulan', 'Flower' , to_date('4/4/2017' , 'mm/dd/yyyy') from dual union all
select 'Mulan', 'Badminton', to_date('11/20/2015', 'mm/dd/yyyy') from dual union all
select 'Mulan', 'Flower' , to_date('11/20/2015', 'mm/dd/yyyy') from dual)
select
max(grp) keep (dense_rank last order by login_date) as grp
from s
group by user_id;
GRP
---------
Flower