1.准备建表和数据
create table u
(
uname varchar2(100),
dt date
);
insert into u values('张三', date'2024-1-1');
insert into u values('张三', date'2024-1-3');
insert into u values('张三', date'2024-1-4');
insert into u values('李四', date'2024-1-4');
insert into u values('李四', date'2024-1-5');
insert into u values('李四', date'2024-1-8');
insert into u values('李四', date'2024-1-11');
insert into u values('王五', date'2024-1-1');
insert into u values('王五', date'2024-1-2');
insert into u values('王五', date'2024-1-3');
commit;
2.查询
select uname from
(
select uname, dt,
dt - row_number()over(partition by uname order by dt) as r
from u
)
group by uname, r
having count(1) >= 3;