ソースコード
WITH LOG AS (
  SELECT SESSION_ID
        ,PROCESS_ID
        ,LAG(PROCESS_ID, 1) OVER(PARTITION BY SESSION_ID ORDER BY EX_TIMESTAMP, PROCESS_ID) B1
        ,LAG(PROCESS_ID, 2) OVER(PARTITION BY SESSION_ID ORDER BY EX_TIMESTAMP, PROCESS_ID) B2
        ,LAG(PROCESS_ID, 3) OVER(PARTITION BY SESSION_ID ORDER BY EX_TIMESTAMP, PROCESS_ID) B3
        ,LAG(PROCESS_ID, 4) OVER(PARTITION BY SESSION_ID ORDER BY EX_TIMESTAMP, PROCESS_ID) B4
    FROM PROCESS_LOG
  ORDER BY SESSION_ID
          ,PROCESS_ID
), LOG_Y AS (
  SELECT PROCESS_ID
        ,SESSION_ID
    FROM LOG
   WHERE PROCESS_ID = 'STEP1'
     AND B1 IS NULL
     AND B2 IS NULL
     AND B3 IS NULL
     AND B4 IS NULL
), LOG_2 AS (
  SELECT L.PROCESS_ID
        ,L.SESSION_ID
    FROM LOG L
   INNER JOIN LOG_Y Y
      ON L.SESSION_ID = Y.SESSION_ID
   WHERE L.PROCESS_ID = 'STEP2'
     AND L.B1 = 'STEP1'
), LOG_3 AS (
  SELECT L.PROCESS_ID
        ,L.SESSION_ID
    FROM LOG L
   INNER JOIN LOG_Y Y
      ON L.SESSION_ID = Y.SESSION_ID
   WHERE L.PROCESS_ID = 'STEP3'
     AND L.B1 = 'STEP2'
     AND L.B2 = 'STEP1'
), LOG_4 AS (
  SELECT L.PROCESS_ID
        ,L.SESSION_ID
    FROM LOG L
   INNER JOIN LOG_Y Y
      ON L.SESSION_ID = Y.SESSION_ID
   WHERE L.PROCESS_ID = 'STEP4'
     AND L.B1 = 'STEP3'
     AND L.B2 = 'STEP2'
     AND L.B3 = 'STEP1'
), LOG_5 AS (
  SELECT L.PROCESS_ID
        ,L.SESSION_ID
    FROM LOG L
   INNER JOIN LOG_Y Y
      ON L.SESSION_ID = Y.SESSION_ID
   WHERE L.PROCESS_ID = 'STEP5'
     AND L.B1 = 'STEP4'
     AND L.B2 = 'STEP3'
     AND L.B3 = 'STEP2'
     AND L.B4 = 'STEP1'
)
SELECT PROCESS_ID PROCESS
      ,COUNT(PROCESS_ID) CNT
  FROM LOG_Y
 GROUP BY PROCESS_ID
UNION
SELECT PROCESS_ID PROCESS
      ,COUNT(PROCESS_ID) CNT
  FROM LOG_2
 GROUP BY PROCESS_ID
UNION
SELECT PROCESS_ID PROCESS
      ,COUNT(PROCESS_ID) CNT
  FROM LOG_3
 GROUP BY PROCESS_ID
UNION
SELECT PROCESS_ID PROCESS
      ,COUNT(PROCESS_ID) CNT
  FROM LOG_4
 GROUP BY PROCESS_ID
UNION
SELECT PROCESS_ID PROCESS
      ,COUNT(PROCESS_ID) CNT
  FROM LOG_5
 GROUP BY PROCESS_ID
 ORDER BY PROCESS_ID
提出情報
提出日時2023/12/17 16:06:15
コンテスト第10回 SQLコンテスト
問題顧客行動分析
受験者yakiniku_tabetai_pakupaku
状態 (詳細)WA
(Wrong Answer: 誤答)
メモリ使用量99 MB
メッセージ
テストケース(通過数/総数)
3/4
状態
メモリ使用量
データパターン1
AC
98 MB
データパターン2
AC
87 MB
データパターン3
AC
99 MB
データパターン4
WA
87 MB