Hmmm . . . You can use row_number()
(twice) and aggregation:
select user,
max(case when seqnum_u = 1 then type end) as type1,
max(case when seqnum_u = 1 then date end) as date1,
max(case when seqnum_u = 2 then type end) as type2,
max(case when seqnum_u = 2 then date end) as date2
from (select t.*,
row_number() over (partition by user order by date) as seqnum_u
from (select t.*,
row_number() over (partition by user, type order by date) as seqnum
from t
) t
where seqnum = 1
) t
group by user;
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…