如果您的应用程序中的阶段以非常严格的顺序定义,您可以使用这种方法或类似的逻辑,并且您可以拥有如下的参考表。
with t2 as
(
select 1 id, 'start' event from dual union all
select 2 id, 'communicating' event from dual union all
select 3 id, 'salecomplete' event from dual
)
select * from t2;
ID EVENT
---------- -------------
1 start
2 communicating
3 salecomplete
您可以在数据中获取 order_id/workflow_id,然后检查是否有任何其他工作流项目应该在该项目之前,但没有。
例如。检查没有“通信”的“完成”事件。(或)检查没有“开始”事件的“通信”事件。
这是代码。我只包含了客户 ID 级别,但将其扩展到与特定客户打交道的用户是相当直接的。
with t1 as (
select 100 cust, 'start' event from dual union all
select 100 cust, 'salecomplete' event from dual union all
select 200 cust, 'communicating' event from dual union all
select 200 cust, 'salecomplete' event from dual union all
select 300 cust, 'salecomplete' event from dual union all
select 400 cust, 'start' event from dual union all
select 400 cust, 'communicating' event from dual union all
select 400 cust, 'salecomplete' event from dual
),
t2 as
(
select 1 id, 'start' event from dual union all
select 2 id, 'communicating' event from dual union all
select 3 id, 'salecomplete' event from dual
),
t3 as
(
select t1.cust, t2.*
from t1, t2
where t1.event = t2.event
)
select * from t3 tgt
where tgt.id <> 1 --initial event can exist by itself
and not exists (
select 1
from t3 src
where tgt.cust = src.cust
and tgt.id -1 = src.id
);
这将显示缺少前一个事件的所有事件。
CUST ID EVENT
---------- ---------- -------------
100 3 salecomplete
200 2 communicating
300 3 salecomplete
要获取发生这种情况的客户列表,只需在最后一个查询中使用 dist cust 即可。
...
CUST
----------
100
200
300