前提:
某施人員(工號)會進行排班施工(有開始結束時間,同一工序持續時間不一定相同), 工序包括某幾個步驟,用逗號分隔。有工號排班表,工序步驟表。
要求:
統計出排班的步驟沖突情況。具體為某一步驟會同時被3個或3個以上施工人員同時占用情況.
求輸出結果: 步驟,工號(同逗號分開),沖突時間(第三個沖突開始時間)
如下例有2個沖突
L1 N1,N2,N3 18:08:20
L4 N1,N3,N4,N7 15:25:02
想通過存過實作, 用游標遍歷排班表,分組統計,count(*)>=3 插入臨時表。寫了半天沒寫出,求大神出手相助。
附:
排班表
工號 開始時間 結束時間 工序
N1 18:02:01 18:30:20 S1
N2 18:07:31 18:31:20 S2
N3 18:08:20 18:35:20 S3
N4 19:00:02 19:10:10 S4
N2 13:02:01 14:30:20 S1
N3 15:07:31 15:31:20 S2
N4 15:08:20 15:35:20 S3
N1 15:25:02 16:10:10 S4
N7 15:26:03 17:10:10 S7
工序 步驟
S1 L1,L2,L3
S2 L1,L4,L5
S3 L1,L4,L7
S4 L2,L4,L8
S7 L3,L4
沖突檢測結果
步驟 工號 沖突時間
L1 N1,N2,N3 18:08:20
L4 N1,N3,N4,N7 15:25:02
uj5u.com熱心網友回復:
declarev_col varchar2(10);
v_col1 varchar2(20);
cursor cur is select col1,to_char(wm_concat(col)) col from (select col,regexp_substr(col1,'[^,]+',1,level) col1 from test1 connect by level <= regexp_count(col1,'[,]')+1 and rowid=prior rowid and (prior dbms_random.value) is not null) group by col1;
begin
for cur_r in cur loop;
select col,start_date from (select id,start_date,end_date,row_number() over(partition by rn order by start_date) rn ,wm_concat(id) over(partition by rn) col from (select id,start_date,end_date,sum(rn) over(order by start_date) rn from
(select id,start_date,end_date,case when rn>0 then 0 else 1 end rn from
(select id,start_date,end_date,lead_end_date-start_date rn from (select id,start_date,end_date,lag(end_date) over(order by start_date) lead_end_date from test where instr('S1,S3,S2',col)>=1) )))) where rn=3;
寫了一個小時 樓主自己去完善一下
insert into test values('N1',to_date('2016-11-23 18:02:01','yyyy-mm-dd hh24:mi:ss'), to_date('2016-11-23 18:30:20','yyyy-mm-dd hh24:mi:ss'),'S1');
insert into test values('N2',to_date('2016-11-23 18:07:31','yyyy-mm-dd hh24:mi:ss'), to_date('2016-11-23 18:31:20','yyyy-mm-dd hh24:mi:ss'),'S2');
insert into test values('N3',to_date('2016-11-23 18:08:20','yyyy-mm-dd hh24:mi:ss'), to_date('2016-11-23 18:35:20','yyyy-mm-dd hh24:mi:ss'),'S3');
insert into test values('N4',to_date('2016-11-23 19:00:02','yyyy-mm-dd hh24:mi:ss'), to_date('2016-11-23 19:10:10','yyyy-mm-dd hh24:mi:ss'),'S4');
insert into test values('N2',to_date('2016-11-23 13:02:01','yyyy-mm-dd hh24:mi:ss'), to_date('2016-11-23 14:30:20','yyyy-mm-dd hh24:mi:ss'),'S1');
insert into test values('N3',to_date('2016-11-23 15:07:31','yyyy-mm-dd hh24:mi:ss'), to_date('2016-11-23 15:31:20','yyyy-mm-dd hh24:mi:ss'),'S2');
insert into test values('N4',to_date('2016-11-23 15:08:20','yyyy-mm-dd hh24:mi:ss'), to_date('2016-11-23 15:35:20','yyyy-mm-dd hh24:mi:ss'),'S3');
insert into test values('N1',to_date('2016-11-23 15:25:02','yyyy-mm-dd hh24:mi:ss'), to_date('2016-11-23 16:10:10','yyyy-mm-dd hh24:mi:ss'),'S4');
insert into test values('N7',to_date('2016-11-23 15:26:03','yyyy-mm-dd hh24:mi:ss'), to_date('2016-11-23 17:10:10','yyyy-mm-dd hh24:mi:ss'),'S7');
insert into test1 values('S1','L1,L2,L3');
insert into test1 values('S2','L1,L4,L5');
insert into test1 values('S3' ,'L1,L4,L7');
insert into test1 values('S4' ,'L2,L4,L8');
insert into test1 values('S7' ,'L3,L4');
uj5u.com熱心網友回復:
select 工號,count(*) from 表 group by 工號 having count(*)>=3
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/110561.html
標籤:高級技術
上一篇:求各位大神指教,sql的問題
下一篇:oracle模糊分組查詢統計
