//先将trlog做简单处理,from_url都置空
insert into table ALLOG
select platform, user_id, seq, null as from_url, m.click_url to_url
from (select platform,
user_id,
rank() over(partition by platform order by click_time) as seq,
click_url
from trlog
group by platform, user_id,click_time,click_url) m;
//在通过自表关联复写from_url
insert overwrite table allog
select a.platform,
a.user_id,
a.seq,
case
when a.seq = 1 then
a.from_url
else
m.to_url
end as from_url,
case
when a.seq = 1 then
a.to_url
else
a.to_url
end as to_url
from (select * from ALLOG) a
left outer join (select platform,
user_id,
seq + 1 as seq,
from_url,
to_url
from ALLOG) m on a.platform = m.platform
and a.user_id = m.user_id
and a.seq = m.seq;