with df as( SELECT user_id, sales_date, dense_rank() over(partition by user_id order by sales_date asc) as "RK", date_add(sales_date,INTERVAL -row_number() over(partition by user_id order by sales_date asc) day) as "辅助列" from sales_tb ) select user_id, count(*) as "days_count" from df group by user_id,辅助列 having days_count>=2 order by user_id asc