ソースコード
WITH T1 AS(
    SELECT
        SESSION_ID,
        CAST(SUBSTR(PROCESS_ID, -1) AS INTEGER) AS PROCESS_ID,
        EX_TIMESTAMP,
        MAX(EX_TIMESTAMP) OVER(
            PARTITION BY SESSION_ID
            ORDER BY PROCESS_ID ASC
        ) AS PRE_TIME,
        MIN(EX_TIMESTAMP) OVER(
            PARTITION BY SESSION_ID
            ORDER BY PROCESS_ID DESC
        ) AS NEXT_TIME
    FROM
        PROCESS_LOG
),
T2 AS(
    SELECT
        SESSION_ID,
        PROCESS_ID,
        COUNT(*) OVER(
            PARTITION BY SESSION_ID
            ORDER BY PROCESS_ID ASC
        ) AS PRE_CNT
    FROM
        T1
    WHERE
        EX_TIMESTAMP = PRE_TIME
        AND EX_TIMESTAMP = NEXT_TIME
),
T3 AS(
    SELECT
        MAX(PROCESS_ID) AS PROCESS_ID,
        COUNT(*) AS CNT
    FROM
        T2
    WHERE
        PROCESS_ID = PRE_CNT
    GROUP BY
        PROCESS_ID
),
T4 AS(
    SELECT
        1 AS PROCESS_ID
    UNION ALL
        SELECT
            PROCESS_ID + 1 AS PROCESS_ID
        FROM T4
        WHERE
            PROCESS_ID < 5
)
SELECT
    'STEP' || T4.PROCESS_ID AS PROCESS,
    CASE
        WHEN T3.CNT IS NULL THEN 0
        ELSE T3.CNT
    END AS CNT
FROM
    T4
    LEFT OUTER JOIN
        T3 ON T4.PROCESS_ID = T3.PROCESS_ID
提出情報
提出日時2023/12/24 12:41:29
コンテスト第10回 SQLコンテスト
問題顧客行動分析
受験者tokusakurai
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量86 MB
メッセージ
テストケース(通過数/総数)
4/4
状態
メモリ使用量
データパターン1
AC
85 MB
データパターン2
AC
85 MB
データパターン3
AC
86 MB
データパターン4
AC
84 MB