
14 PUZZLE 3 THE ANESTHESIA PUZZLE
Answer #3
This answer came from Lex van de Pol (aavdpol@hotmail.com) on June
9, 2000. The idea is to loop through all procedures (
P1); for each
procedure
P1 you look at procedures P2 where their start time lies in the
interval of procedure
P2. For each start time you found of P2, count the
number of procedures (
P3) that are ongoing on that time. Then, take the
maximum count for a certain procedure
P1.
For doing this, Lex first created this view:
CREATE VIEW Vprocs (id1, id2, total)
AS SELECT P1.prc_id, P2.prc_id, COUNT(*)
FROM Procs AS P1, Procs AS P2, Procs AS P3
WHERE P2.ant_name = P1.ant_name
AND P3.ant_name ...