sql >> Base de Datos >  >> RDS >> PostgreSQL

Encuentre suscriptores que no se volvieron a suscribir dentro del umbral de la suscripción anterior

No existe debe hacer lo que quieras:

select t.*
from t
where ends_at >= '2019-03-01' and ends_at < '2019-04-01' and
      not exists (select 1
                  from t t2
                  where t2.user_id = t.user_id and
                        t2.starts_at >= t.ends_at and
                        t2.starts_at <= t.ends_at + interval '2 day'
                 );