17,086
社区成员
发帖
与我相关
我的任务
分享
with t as (
select 1 as id,1 bm,'001' as dno,to_date('201609010831','yyyymmddhh24miss') as sj from dual union all
select 2 as id,1 bm,'001' as dno,to_date('201609010910','yyyymmddhh24miss') as sj from dual union all
select 3 as id,1 bm,'001' as dno,to_date('201609011031','yyyymmddhh24miss') as sj from dual union all
select 4 as id,1 bm,'001' as dno,to_date('201609011135','yyyymmddhh24miss') as sj from dual union all
select 5 as id,1 bm,'001' as dno,to_date('201609011215','yyyymmddhh24miss') as sj from dual union all
select 6 as id,2 bm,'001' as dno,to_date('201609011331','yyyymmddhh24miss') as sj from dual union all
select 7 as id,2 bm,'001' as dno,to_date('201609011432','yyyymmddhh24miss') as sj from dual union all
select 8 as id,1 bm,'002' as dno,to_date('201609011531','yyyymmddhh24miss') as sj from dual union all
select 9 as id,1 bm,'002' as dno,to_date('201609011210','yyyymmddhh24miss') as sj from dual)
select t1.*
from t t1,t t2
where t1.dno=t2.dno
and t1.bm=t2.bm --加一个部门匹配就好
and t1.id<>t2.id
and abs(t1.sj-t2.sj)<1/24
order by 1;
with t as (
select 1 as id,'001' as dno,to_date('201609010831','yyyymmddhh24miss') as sj from dual union all
select 2 as id,'001' as dno,to_date('201609010910','yyyymmddhh24miss') as sj from dual union all
select 3 as id,'001' as dno,to_date('201609011031','yyyymmddhh24miss') as sj from dual union all
select 4 as id,'001' as dno,to_date('201609011135','yyyymmddhh24miss') as sj from dual union all
select 5 as id,'001' as dno,to_date('201609011215','yyyymmddhh24miss') as sj from dual union all
select 6 as id,'001' as dno,to_date('201609011331','yyyymmddhh24miss') as sj from dual union all
select 7 as id,'001' as dno,to_date('201609011432','yyyymmddhh24miss') as sj from dual union all
select 8 as id,'002' as dno,to_date('201609011531','yyyymmddhh24miss') as sj from dual union all
select 9 as id,'002' as dno,to_date('201609011210','yyyymmddhh24miss') as sj from dual)
select t1.*
from t t1,t t2
where t1.dno=t2.dno
and t1.id<>t2.id
and abs(t1.sj-t2.sj)<1/24
order by 1;
with t as (
select 1 as id,'001' as dno,'201609010831'as sj from dual
union all
select 2 as id,'001' as dno,'201609010910'as sj from dual
union all
select 3 as id,'001' as dno,'201609011031'as sj from dual
union all
select 4 as id,'001' as dno,'201609011135'as sj from dual
union all
select 5 as id,'001' as dno,'201609011215'as sj from dual
union all
select 6 as id,'001' as dno,'201609011331'as sj from dual
union all
select 7 as id,'001' as dno,'201609011432'as sj from dual
union all
select 8 as id,'002' as dno,'201609011531'as sj from dual
union all
select 9 as id,'002' as dno,'201609011210'as sj from dual
)
select t1.* from
(
select id,dno,lag(TO_date(sj,'YYYY-MM-DD hh24:mi:ss'),1) over(partition by dno order by sj) p_sj,
TO_date(sj,'YYYY-MM-DD hh24:mi:ss') sj,
lead(TO_date(sj,'YYYY-MM-DD hh24:mi:ss'),1) over(partition by dno order by sj) n_sj
from t
) t1
where ROUND(TO_NUMBER(sj-p_sj)*24*60)<60 or ROUND(TO_NUMBER(n_sj-sj)*24*60)<60
对于id是8和9的两条记录,时间间隔已经大于1小时了怎么还在结果里?