ソースコード
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
        )
), T3 AS(
    SELECT
        MAX(PROCESS_ID) AS PROCESS_ID,
        COUNT(*) AS CNT
    FROM
        T2
    GROUP BY
        PROCESS_ID
    ORDER BY
        PROCESS_ID ASC
), T4 AS(
    SELECT
        1 AS PROCESS_ID
    UNION ALL
        SELECT
            PROCESS_ID + 1 AS PROCESS_ID
        FROM T4
        WHERE
            PROCESS_ID < 5
), T5 AS(
    SELECT
        'STEP' || T4.PROCESS_ID AS PROCESS,
        CASE
            WHEN T3.CNT IS NULL THEN 0
            ELSE T3.CNT
        END AS CNT
    FROM
        T4
        INNER JOIN
            T3 ON T4.PROCESS_ID = T3.PROCESS_ID
)
SELECT
    *
FROM
    T5
提出情報
提出日時2023/12/17 10:55:53
コンテスト第10回 SQLコンテスト
問題顧客行動分析
受験者tokusakurai
状態 (詳細)WA
(Wrong Answer: 誤答)
メモリ使用量86 MB
メッセージ
テストケース(通過数/総数)
3/4
状態
メモリ使用量
データパターン1
AC
84 MB
データパターン2
AC
86 MB
データパターン3
AC
86 MB
データパターン4
WA
85 MB