アプリケーションのステージが非常に厳密な順序で定義されていて、以下のような参照テーブルを使用できる場合は、このアプローチまたは同様のロジックを使用できます。
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 を取得し、このアイテムの前にあるはずの他のワークフロー アイテムがあるかどうかを確認できますが、そうではありません。
例えば。「通信中」のない「完了」イベントをチェックします。(または) "Start" イベントがない "communicating" イベントをチェックします。
これがコードです。顧客 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