1、这段代码的作用在于获取麻醉的开始事件和结束事件
use
Test
go
create
view
Event_s
(
proc_id
,
comparison_proc
,
anest_name
,
event_time
,
event_type
)
as
select
p1
.
proc_id
,
p2
.
proc_id
,
p1
.
anest_name
,
p2
.
start_time
,+
1
from
Procs
as
p1
,
Procs
as
p2
where
p1
.
anest_name
=
p2
.
anest_name
and
not
(
p2
.
end_time
<=
p1
.
start_time
or
p2
.
start_time
>=
p1
.
end_time
)
union
select
p1
.
proc_id
,
p2
.
proc_id
,
p1
.
anest_name
,
p2
.
start_time
,-
1
as
event_tyepe
from
Procs
as
p1
,
Procs
as
p2
where
p1
.
anest_name
=
p2
.
anest_name
and
not
(
p2
.
end_time
<=
p1
.
start_time
or
p2
.
start_time
>=
p1
.
end_time
)
go
对于Dow#30麻醉过程来说,Dow#40、Dow#50、Dow#6、Dow#70是
开始事件
,Dow#40、Dow#50、Dow#60、Dow#70也是
结束事件
结合图片可以发现,以Dow#30麻醉过程为准,将所有麻醉过程与之对比,只有存在交叉的则必须统计在Dow#30麻醉过程的开始事件和结束事件。因此,只要统计“与Dow#30麻醉过程交叉的过程”的开始事件和结束事件即可。
那么,统计
“与Dow#30麻醉过程交叉的过程”
的相反事件即为
“与Dow#30麻醉过程不交叉的过程”。
“与Dow#30麻醉过程不交叉的过程”实际上只存在两种情况
①②和
②③
:
(1)对于②来说,①②③三个麻醉过程满足不交叉的条件:以②为基准,
②的开始时间>=①的结束时间,②的结束时间<=③的开始时间。
只要满足这个两个条件其中之一,则不会将不交叉的麻醉过程统计到最大次数的计算中。剩余的所有麻醉过程计算相关的开始事件与结束事件。
2、以下的SQL语句是把对所有开始事件和结束事件进行累加,计算出需要统计在麻醉过程中的所有中的每个节点的值。
select
e1
.
proc_id
,
e1
.
event_time
,
(
select
sum