ソースコード
INSERT INTO
    PROCESS_LOG VALUES("aiueo", "STEP1", 0, "2023-11-01 00:01:00");
INSERT INTO
    PROCESS_LOG VALUES("aiueo", "STEP2", 0, "2023-11-01 00:02:00");
    INSERT INTO
    PROCESS_LOG VALUES("aiueo", "STEP3", 0, "2023-11-01 00:03:00");
INSERT INTO
    PROCESS_LOG VALUES("aiueo", "STEP4", 0, "2023-11-01 00:04:00");
INSERT INTO
    PROCESS_LOG VALUES("aiueo", "STEP5", 0, "2023-11-01 00:05:00");
WITH T1 AS(
    SELECT
        MAX(P1.SESSION_ID) AS SESSION_ID,
        MAX(CAST(SUBSTR(P1.PROCESS_ID, -1) AS INTEGER)) AS PROCESS_ID
    FROM
        PROCESS_LOG AS P1
        CROSS JOIN
            PROCESS_LOG AS P2
    WHERE
        P1.SESSION_ID = P2.SESSION_ID
    GROUP BY
        P1.SESSION_ID,
        P1.PROCESS_ID
    HAVING
        (
            MAX(
                CASE
                    WHEN P2.PROCESS_ID < P1.PROCESS_ID THEN P2.EX_TIMESTAMP
                    ELSE NULL
                END
            ) IS NULL OR MAX(P1.EX_TIMESTAMP) > MAX(
                CASE
                    WHEN P2.PROCESS_ID < P1.PROCESS_ID THEN P2.EX_TIMESTAMP
                    ELSE NULL
                END
            ) 
        ) AND (
            MIN(
                CASE
                    WHEN P2.PROCESS_ID > P1.PROCESS_ID THEN P2.EX_TIMESTAMP
                    ELSE NULL
                END
            ) IS NULL OR MAX(P1.EX_TIMESTAMP) < MIN(
                CASE
                    WHEN P2.PROCESS_ID > P1.PROCESS_ID THEN P2.EX_TIMESTAMP
                    ELSE NULL
                END
            )
        )
), T2 AS(
    SELECT
        MAX(P1.SESSION_ID) AS SESSION_ID,
        MAX(P1.PROCESS_ID) AS PROCESS_ID
    FROM
        T1 AS P1
        CROSS JOIN
            T1 AS P2
    WHERE
        P1.SESSION_ID = P2.SESSION_ID
    GROUP BY
        P1.SESSION_ID,
        P1.PROCESS_ID
    HAVING
        MAX(P1.PROCESS_ID) = SUM(
            CASE
                WHEN P2.PROCESS_ID <= P1.PROCESS_ID THEN 1
                ELSE 0
            END
        )
)
SELECT
    'STEP' || MAX(PROCESS_ID) AS PROCESS,
    COUNT(*) - 1 AS CNT
FROM
    T2
GROUP BY
    PROCESS_ID
ORDER BY
    PROCESS ASC
提出情報
提出日時2023/12/17 00:37:57
コンテスト第10回 SQLコンテスト
問題顧客行動分析
受験者tokusakurai
状態 (詳細)WA
(Wrong Answer: 誤答)
メモリ使用量86 MB
メッセージ
テストケース(通過数/総数)
0/4
状態
メモリ使用量
データパターン1
WA
83 MB
データパターン2
WA
83 MB
データパターン3
WA
86 MB
データパターン4
WA
84 MB