Use a window function to get the minimum date. Then aggregate:
select user,
count(*) filter (where date > min_date and date < min_date + interval '8 month')
from (select t.*, min(date) over (partition by user) as min_date
from t
) t
group by user;
Here is a db<>fiddle.
Note: user
is a reserved word so it should not be used as a column name.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…