ソースコード

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 r
    FROM
        PROCESS_LOG
)


SELECT o1.PROCESS_ID AS PROCESS, count(*) AS "CNT"
FROM OrderedLogs o1
WHERE r = 1 AND o1.PROCESS_ID = 'STEP1'
UNION ALL
SELECT o2.PROCESS_ID AS PROCESS, count(*) AS "CNT"
FROM OrderedLogs o2
WHERE r = 2 AND PROCESS_ID = 'STEP2'
AND EXISTS (SELECT * FROM OrderedLogs o21 WHERE r = 1 AND o21.PROCESS_ID = 'STEP1' AND o2.SESSION_ID = o21.SESSION_ID)
UNION ALL
SELECT PROCESS_ID AS PROCESS, count(*) AS "CNT"
FROM OrderedLogs o3
WHERE r = 3 AND PROCESS_ID = 'STEP3'
AND EXISTS (SELECT * FROM OrderedLogs o32 WHERE r = 2 AND o32.PROCESS_ID = 'STEP2' AND o3.SESSION_ID = o3.SESSION_ID)
AND EXISTS (SELECT * FROM OrderedLogs o31 WHERE r = 1 AND o31.PROCESS_ID = 'STEP1' AND o3.SESSION_ID = o3.SESSION_ID)
UNION ALL
SELECT PROCESS_ID AS PROCESS, count(*) AS "CNT"
FROM OrderedLogs o4
WHERE r = 4 AND PROCESS_ID = 'STEP4'
AND EXISTS (SELECT * FROM OrderedLogs o43 WHERE r = 3 AND PROCESS_ID = 'STEP3' AND o4.SESSION_ID = o43.SESSION_ID)
AND EXISTS (SELECT * FROM OrderedLogs o42 WHERE r = 2 AND PROCESS_ID = 'STEP2' AND o4.SESSION_ID = o42.SESSION_ID)
AND EXISTS (SELECT * FROM OrderedLogs o41 WHERE r = 1 AND PROCESS_ID = 'STEP1' AND o4.SESSION_ID = o41.SESSION_ID)
UNION ALL
SELECT PROCESS_ID AS PROCESS, count(*) AS "CNT"
FROM OrderedLogs o5
WHERE r = 5 AND PROCESS_ID = 'STEP5'
AND EXISTS (SELECT * FROM OrderedLogs o54 WHERE r = 4 AND PROCESS_ID = 'STEP4' AND o5.SESSION_ID = o54.SESSION_ID)
AND EXISTS (SELECT * FROM OrderedLogs o53 WHERE r = 3 AND PROCESS_ID = 'STEP3' AND o5.SESSION_ID = o53.SESSION_ID)
AND EXISTS (SELECT * FROM OrderedLogs o52 WHERE r = 2 AND PROCESS_ID = 'STEP2' AND o5.SESSION_ID = o52.SESSION_ID)
AND EXISTS (SELECT * FROM OrderedLogs o51 WHERE r = 1 AND PROCESS_ID = 'STEP1' AND o5.SESSION_ID = o51.SESSION_ID)
提出情報
提出日時2023/12/17 13:05:59
コンテスト第10回 SQLコンテスト
問題顧客行動分析
受験者swamp
状態 (詳細)WA
(Wrong Answer: 誤答)
メモリ使用量87 MB
メッセージ
テストケース(通過数/総数)
2/4
状態
メモリ使用量
データパターン1
AC
85 MB
データパターン2
AC
87 MB
データパターン3
WA
87 MB
データパターン4
WA
84 MB