1

私はこの問題を解決しなければなりませんが、効果的に説明できることを願っています。

  • イベントの操作順序は、開始→通信→販売完了
  • Statusの操作順序: Working → Complete

すべてのユーザーがプロセスに従っており、手順をスキップしていないことを確認する必要があります

この例のように:

テーブルの例

  • Bobo は 2 つのクライアントと連携しています
    • 最初のクライアントはまだ通信段階ですが、操作順序のプロセスに従っています
    • しかし、彼の 2 番目のクライアントでは、通信に進む前に開始のステータスを完了していませんでした。
  • Mike は、Working ステータスの Start イベントから、Complete ステータスの Communicating イベント、Working ステータスの Sale Complete イベントに移行しました。そのため、マイクも操作の順序に従っていません。

明らかに、このような非常に小さなスケールでは、これを少し見るだけでそれを確認できます。残念ながら、私たちは常に何百人ものユーザーと何千もの顧客と一緒に仕事をしています。

私が必要とするのは、プロセスが実行されていない顧客 ID の数だけです (完全なプロセスが完了していないという問題ではありません)。

結果は次のようになると思います

Bobo     1
Mike     1

つまり、Bobo は 1 つのアカウントに取り組んでおり、Mike と同じように手順をスキップしました。

4

2 に答える 2

0

アプリケーションのステージが非常に厳密な順序で定義されていて、以下のような参照テーブルを使用できる場合は、このアプローチまたは同様のロジックを使用できます。

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
于 2013-02-06T21:39:27.740 に答える
0

テーブル構造でやりたいことができません。SQL では、テーブルは本質的に順不同です。最初と2番目に何が起こったのかを知る方法はありません。

その情報がなければ、シーケンスを決定することは不可能です。

行を注文するIDまたは日時はありますか?

このようなフィールドを使用すると、次のステータスを取得できます。

select t.*,
       lead(EVENT) over (partition by username, customerid order by thedatetime) as nextEvent,
       lead(status) over (partition by username, customerid order by thedatetime) as nextStatus
from t

次に、ロジックを使用できます。

select t.*
from (select t.*,
             lead(EVENT) over (partition by username, customerid order by thedatetime) as nextEvent,
             lead(status) over (partition by username, customerid order by thedatetime) as nextStatus
      from t
     ) t
where not (event = 'Start' and coalesce(nextEvent, 'Communicating') = 'Communicating' or
           event = 'Communicating' and coalesce(nextEvent, 'Sale Complete') = 'Sale Complete' or
           event = 'Sale Complete' and nextEvent is not null or
           status = 'Working' and coalesce(nextstatus, 'Complete') = 'Complete' or
           status = 'Complete' and nextstatus is not null
          )

これにより、すべての情報が得られます。customerIds のみが必要な場合は、次を使用します。

select distinct CustomerId
于 2013-02-06T21:31:56.750 に答える