ソースコード
WITH OrderedSteps AS (
    SELECT 
        SESSION_ID, 
        PROCESS_ID, 
        ROW_NUMBER() OVER (PARTITION BY SESSION_ID ORDER BY EX_TIMESTAMP) AS StepOrder
    FROM 
        PROCESS_LOG
),
ValidSessions AS (
    SELECT 
        SESSION_ID, 
        MAX(CASE WHEN PROCESS_ID = 'STEP1' THEN StepOrder ELSE 0 END) AS Step1Order,
        MAX(CASE WHEN PROCESS_ID = 'STEP2' THEN StepOrder ELSE 0 END) AS Step2Order,
        MAX(CASE WHEN PROCESS_ID = 'STEP3' THEN StepOrder ELSE 0 END) AS Step3Order,
        MAX(CASE WHEN PROCESS_ID = 'STEP4' THEN StepOrder ELSE 0 END) AS Step4Order,
        MAX(CASE WHEN PROCESS_ID = 'STEP5' THEN StepOrder ELSE 0 END) AS Step5Order
    FROM 
        OrderedSteps
    GROUP BY 
        SESSION_ID
    HAVING 
        Step1Order = 1 AND
        (Step2Order = 0 OR Step2Order = 2) AND
        (Step3Order = 0 OR Step3Order = 3) AND
        (Step4Order = 0 OR Step4Order = 4) AND
        (Step5Order = 0 OR Step5Order = 5)
),
LastValidStep AS (
    SELECT 
        SESSION_ID, 
        CASE 
            WHEN Step5Order = 5 THEN 'STEP5'
            WHEN Step4Order = 4 THEN 'STEP4'
            WHEN Step3Order = 3 THEN 'STEP3'
            WHEN Step2Order = 2 THEN 'STEP2'
            ELSE 'STEP1'
        END AS LastStep
    FROM 
        ValidSessions
)
SELECT 
    LastStep AS PROCESS, 
    COUNT(*) AS CNT
FROM 
    LastValidStep
GROUP BY 
    LastStep
ORDER BY 
    PROCESS;
提出情報
提出日時2023/12/17 23:14:48
コンテスト第10回 SQLコンテスト
問題顧客行動分析
受験者sql_yowayowa
状態 (詳細)WA
(Wrong Answer: 誤答)
メモリ使用量89 MB
メッセージ
テストケース(通過数/総数)
0/4
状態
メモリ使用量
データパターン1
WA
87 MB
データパターン2
WA
86 MB
データパターン3
WA
89 MB
データパターン4
WA
84 MB