窗口函数增加新的排序一列 之后case when select a.user_id,a.active_dt,a.active_days from (select *, (case when active_day<=3 then active_day else 1 end)active_days from( select user_id, active_dt, row_number() over (partition by user_id order by active_dt )as active_day from table1) t)a ;