17,086
社区成员
发帖
与我相关
我的任务
分享
with tab1 as(
select 'a' id, date'2020-01-02' dat from dual union all
select 'a' id, date'2020-01-03' from dual union all
select 'a' id, date'2020-01-04' from dual union all
select 'a' id, date'2020-01-05' from dual union all
select 'b' id, date'2020-01-02' from dual union all
select 'b' id, date'2020-04-02' from dual
)
, tab2 as (
select t1.*,
count(1) over(partition by t1.id order by t1.dat range between interval '0' month preceding and interval '2' month following) cot
from tab1 t1
)
select t1.id from tab2 t1
group by t1.id
having count(case when t1.cot > 2 then 1 else null end) > 0