ソースコード
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(*) AS CNT
FROM
    T2
GROUP BY
    PROCESS_ID
ORDER BY
    PROCESS ASC
提出情報
提出日時2023/12/16 23:59:53
コンテスト第10回 SQLコンテスト
問題顧客行動分析
受験者tokusakurai
状態 (詳細)WA
(Wrong Answer: 誤答)
メモリ使用量86 MB
メッセージ
テストケース(通過数/総数)
3/4
状態
メモリ使用量
データパターン1
AC
86 MB
データパターン2
AC
85 MB
データパターン3
AC
85 MB
データパターン4
WA
85 MB