RedInTheCorner
Programmer
Hello everyone,
I have little bit problem with a query. Query's aim is getting max number of intersections of processes. My table is
PROCESS_TEST
Process StartDate EndDate
1 01/02/2006 02/03/2006
2 04/02/2006 07/03/2006
3 05/02/2006 08/0372006
4 03/01/2006 27/01/2006
for above sample max number of intercestions is 3
because in the time range 05/02/2006 to 02/03/2006 I have 1, 2 and 3 process alive
my solution is
----
you may need following:
CREATE TABLE PROCESS_TEST
(Process NUMBER(4) PRIMARY KEY,
StartDate DATE,
EndDate DATE);
INSERT INTO PROCESS_TEST VALUES (1, TO_DATE('01/02/2006', 'dd/mm/yyyy'), TO_DATE('02/03/2006', 'dd/mm/yyyy'));
INSERT INTO PROCESS_TEST VALUES (2, TO_DATE('04/02/2006', 'dd/mm/yyyy'), TO_DATE('07/03/2006', 'dd/mm/yyyy'));
INSERT INTO PROCESS_TEST VALUES (3, TO_DATE('05/02/2006', 'dd/mm/yyyy'), TO_DATE('08/03/2006', 'dd/mm/yyyy'));
INSERT INTO PROCESS_TEST VALUES (4, TO_DATE('03/01/2006', 'dd/mm/yyyy'), TO_DATE('27/01/2006', 'dd/mm/yyyy'));
----
SELECT MAX(X) FROM
(
SELECT COUNT(*) X
FROM PROCESS_TEST P1, PROCESS_TEST P2
WHERE P1.EndDate > P2.StartDate
aND P2.EndDate > P1.StartDate
GROUP BY P1.Process
);
it works cool but it would be costly when we have more process I cannot imagine how it would be if I have 1 million process....
Do you have any other idea?
with my best wishes
Atilla
I have little bit problem with a query. Query's aim is getting max number of intersections of processes. My table is
PROCESS_TEST
Process StartDate EndDate
1 01/02/2006 02/03/2006
2 04/02/2006 07/03/2006
3 05/02/2006 08/0372006
4 03/01/2006 27/01/2006
for above sample max number of intercestions is 3
because in the time range 05/02/2006 to 02/03/2006 I have 1, 2 and 3 process alive
my solution is
----
you may need following:
CREATE TABLE PROCESS_TEST
(Process NUMBER(4) PRIMARY KEY,
StartDate DATE,
EndDate DATE);
INSERT INTO PROCESS_TEST VALUES (1, TO_DATE('01/02/2006', 'dd/mm/yyyy'), TO_DATE('02/03/2006', 'dd/mm/yyyy'));
INSERT INTO PROCESS_TEST VALUES (2, TO_DATE('04/02/2006', 'dd/mm/yyyy'), TO_DATE('07/03/2006', 'dd/mm/yyyy'));
INSERT INTO PROCESS_TEST VALUES (3, TO_DATE('05/02/2006', 'dd/mm/yyyy'), TO_DATE('08/03/2006', 'dd/mm/yyyy'));
INSERT INTO PROCESS_TEST VALUES (4, TO_DATE('03/01/2006', 'dd/mm/yyyy'), TO_DATE('27/01/2006', 'dd/mm/yyyy'));
----
SELECT MAX(X) FROM
(
SELECT COUNT(*) X
FROM PROCESS_TEST P1, PROCESS_TEST P2
WHERE P1.EndDate > P2.StartDate
aND P2.EndDate > P1.StartDate
GROUP BY P1.Process
);
it works cool but it would be costly when we have more process I cannot imagine how it would be if I have 1 million process....
Do you have any other idea?
with my best wishes
Atilla