ソースコード
WITH OrderedLogs AS (
    SELECT
        SESSION_ID,
        PROCESS_ID,
        EX_TIMESTAMP,
        -- LEAD(PROCESS_ID) OVER (PARTITION BY SESSION_ID ORDER BY EX_TIMESTAMP) AS NEXT_PROCESS_ID
        RANK () OVER (PARTITION BY SESSION_ID ORDER BY EX_TIMESTAMP) AS RANK
    FROM
        PROCESS_LOG
)

SELECT "STEP1" AS PROCESS, count(*) AS "CNT"
FROM OrderedLogs
WHERE RANK = 1 AND PROCESS_ID = 'STEP1'
UNION ALL
SELECT "STEP2" AS PROCESS, count(*) AS "CNT"
FROM OrderedLogs
WHERE RANK = 2 AND PROCESS_ID = 'STEP2'
AND EXISTS (SELECT * FROM OrderedLogs WHERE RANK = 1 AND PROCESS_ID = 'STEP1' AND SESSION_ID = OrderedLogs.SESSION_ID)
UNION ALL
SELECT "STEP3" AS PROCESS, count(*) AS "CNT"
FROM OrderedLogs
WHERE RANK = 3 AND PROCESS_ID = 'STEP3'
AND EXISTS (SELECT * FROM OrderedLogs WHERE RANK = 2 AND PROCESS_ID = 'STEP2' AND SESSION_ID = OrderedLogs.SESSION_ID)
AND EXISTS (SELECT * FROM OrderedLogs WHERE RANK = 1 AND PROCESS_ID = 'STEP1' AND SESSION_ID = OrderedLogs.SESSION_ID)
UNION ALL
SELECT "STEP4" AS PROCESS, count(*) AS "CNT"
FROM OrderedLogs
WHERE RANK = 4 AND PROCESS_ID = 'STEP4'
AND EXISTS (SELECT * FROM OrderedLogs WHERE RANK = 3 AND PROCESS_ID = 'STEP3' AND SESSION_ID = OrderedLogs.SESSION_ID)
AND EXISTS (SELECT * FROM OrderedLogs WHERE RANK = 2 AND PROCESS_ID = 'STEP2' AND SESSION_ID = OrderedLogs.SESSION_ID)
AND EXISTS (SELECT * FROM OrderedLogs WHERE RANK = 1 AND PROCESS_ID = 'STEP1' AND SESSION_ID = OrderedLogs.SESSION_ID)
UNION ALL
SELECT "STEP5" AS PROCESS, count(*) AS "CNT"
FROM OrderedLogs
WHERE RANK = 5 AND PROCESS_ID = 'STEP5'
AND EXISTS (SELECT * FROM OrderedLogs WHERE RANK = 4 AND PROCESS_ID = 'STEP4' AND SESSION_ID = OrderedLogs.SESSION_ID)
AND EXISTS (SELECT * FROM OrderedLogs WHERE RANK = 3 AND PROCESS_ID = 'STEP3' AND SESSION_ID = OrderedLogs.SESSION_ID)
AND EXISTS (SELECT * FROM OrderedLogs WHERE RANK = 2 AND PROCESS_ID = 'STEP2' AND SESSION_ID = OrderedLogs.SESSION_ID)
AND EXISTS (SELECT * FROM OrderedLogs WHERE RANK = 1 AND PROCESS_ID = 'STEP1' AND SESSION_ID = OrderedLogs.SESSION_ID)
提出情報
提出日時2023/12/17 12:50:29
コンテスト第10回 SQLコンテスト
問題顧客行動分析
受験者swamp
状態 (詳細)WA
(Wrong Answer: 誤答)
メモリ使用量89 MB
メッセージ
テストケース(通過数/総数)
1/4
状態
メモリ使用量
データパターン1
WA
86 MB
データパターン2
WA
89 MB
データパターン3
WA
87 MB
データパターン4
AC
84 MB