with t as (select *,lag(访问的页面)over(partition by 用户ID order by 访问页面时间) as 上一次访问页面 from 访问记录表) select 用户ID,访问的页面,访问页面时间 from t where 上一次访问页面 != 访问的页面 or 上一次访问页面 is null order by 用户ID,访问页面时间