oracle数据库 统计归属标识restype为00、01、02的记录连续7个工作日不能为0的SQL如何写?急求!!!

申请人name,申请时间 reqtime,类型restype
2025-04-05 22:24:57
推荐回答(1个)
回答1:

select *
from (
select restype,reqtime,Flag-RN as Flag2,count(Flag-RN) over (partition by restype,(Flag-RN)) as Flag3
from (
select restype,reqtime,( trunc(sysdate,'DD')-trunc(reqtime,'DD') ) as Flag,
row_number() over (partition by restype order by reqtime) as RN
from (select distinct restype,reqtime from temp) t1
) t2
) t3
where Flag3>=7