We have processes which connect to a subsystem and we are tracking them by this timestamp. What I would like to find out is the maximum number of processes have connected in a time interval of N minutes.
This time interval is the TIMEOUT interval of a process so the countdown of the elapsed time starts when it connects. So the interval is a "floating" interval.
For simplicity, the length of this interval is 5 minutes, the connection times are in minutes and not in milliseconds.
We already have a PL/SQL function to calculate this number but I would like to know if it is possible to do it using only an SQL.
Example:
09:10 09:15 09:20 09:25 09:30
| | | | |
----|--|--|--|--|--|--|--|--|--|--|--|--|--|--|--|--|--|--|--|--|---
| | | | |
| | | | | | | | | | |
a b c a c a b c d a f <-- PROCESSES
f b <-- PROCESSES
Here is SQL for the PROCESSES table:
create table PRCS
(
prc_id NUMBER(12) not null,
prc_name VARCHAR2(25) not null
);
alter table PRCS add constraint PRCS_PK primary key (PRC_ID);
alter table PRCS add constraint PRCS_UK unique (PRC_NAME);
insert into PRCS values('1', 'a');
insert into PRCS values('2', 'b');
insert into PRCS values('3', 'c');
insert into PRCS values('4', 'd');
insert into PRCS values('5', 'e');
insert into PRCS values('6', 'f');
Here is SQL for the CONNECTIONS table:
create table CON_JOURNAL
(
con_id NUMBER(12) not null,
con_date TIMESTAMP(6) not null,
con_prc NUMBER(12) not null
)
;
alter table CON_JOURNAL add constraint CON_PK primary key (CON_ID);
alter table CON_JOURNAL add constraint CON_UK unique (CON_DATE, CON_PRC);
alter table CON_JOURNAL add constraint CON_PRC_FK foreign key (CON_PRC)
references PRCS (PRC_ID);
insert into CON_JOURNAL values( '1', to_date('2013.01.09 09:12', 'yyyy.mm.dd hh24:mi'), '1');
insert into CON_JOURNAL values( '2', to_date('2013.01.09 09:13', 'yyyy.mm.dd hh24:mi'), '2');
insert into CON_JOURNAL values( '3', to_date('2013.01.09 09:14', 'yyyy.mm.dd hh24:mi'), '3');
insert into CON_JOURNAL values( '4', to_date('2013.01.09 09:18', 'yyyy.mm.dd hh24:mi'), '1');
insert into CON_JOURNAL values( '5', to_date('2013.01.09 09:19', 'yyyy.mm.dd hh24:mi'), '3');
insert into CON_JOURNAL values( '6', to_date('2013.01.09 09:21', 'yyyy.mm.dd hh24:mi'), '1');
insert into CON_JOURNAL values( '7', to_date('2013.01.09 09:22', 'yyyy.mm.dd hh24:mi'), '2');
insert into CON_JOURNAL values( '8', to_date('2013.01.09 09:23', 'yyyy.mm.dd hh24:mi'), '3');
insert into CON_JOURNAL values( '9', to_date('2013.01.09 09:24', 'yyyy.mm.dd hh24:mi'), '4');
insert into CON_JOURNAL values('10', to_date('2013.01.09 09:24', 'yyyy.mm.dd hh24:mi'), '6');
insert into CON_JOURNAL values('11', to_date('2013.01.09 09:26', 'yyyy.mm.dd hh24:mi'), '1');
insert into CON_JOURNAL values('12', to_date('2013.01.09 09:26', 'yyyy.mm.dd hh24:mi'), '2');
insert into CON_JOURNAL values('13', to_date('2013.01.09 09:29', 'yyyy.mm.dd hh24:mi'), '6');
Thank you for your help,
SK