select user_id,max(counts) as days_count
from (
select user_id,d,count(*) as counts
from (
select user_id,date_sub(sales_date,interval rk day) as d
from (
select *,
row_number () over(partition by user_id order by sales_date) as rk
from sales_tb
) as rk
) as d
group by user_id,d
) as c
group by user_id
having max(counts)>=2
order by user_id

京公网安备 11010502036488号