By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
with Your_Table (ID, last_logged) as (
select 123, to_date('2021-08-01', 'YYYY-MM-DD') from dual union all
select 123, to_date('2021-07-01', 'YYYY-MM-DD') from dual union all
select 123, to_date('2021-06-01', 'YYYY-MM-DD') from dual union all
select 444, to_date('2021-04-02', 'YYYY-MM-DD') from dual union all
select 444, to_date('2021-05-10', 'YYYY-MM-DD') from dual union all
select 444, to_date('2021-05-11', 'YYYY-MM-DD') from dual
)
, last_three_months (dt) as (
select add_months(sysdate, -level) dt from dual
connect by level <= 3
)
select ID
from Your_Table t1
join last_three_months t2
on trunc(t1.last_logged, 'MONTH') = trunc(t2.dt, 'MONTH')
group by ID
having count(*) = 3
;
ID |
---|
123 |