ソースコード
WITH
    session1 AS (
        SELECT
            SESSION_ID
          , USER_ID
          , MIN(EX_TIMESTAMP) AS min_EX_TIMESTAMP
        FROM
            PROCESS_LOG
        WHERE
            PROCESS_ID = 'STEP1'
        GROUP BY
            SESSION_ID
          , USER_ID
    )
  , session2 AS (
        SELECT
            p.SESSION_ID
          , p.USER_ID
          , MIN(p.EX_TIMESTAMP) AS min_EX_TIMESTAMP
        FROM
            PROCESS_LOG p
            INNER JOIN session1 s1 ON p.SESSION_ID = s1.SESSION_ID
            AND p.USER_ID = s1.USER_ID
        WHERE
            p.PROCESS_ID = 'STEP2'
            AND p.EX_TIMESTAMP > s1.min_EX_TIMESTAMP
        GROUP BY
            p.SESSION_ID
          , p.USER_ID
    )
  , session3 AS (
        SELECT
            p.SESSION_ID
          , p.USER_ID
          , MIN(p.EX_TIMESTAMP) AS min_EX_TIMESTAMP
        FROM
            PROCESS_LOG p
            INNER JOIN session2 s2 ON p.SESSION_ID = s2.SESSION_ID
            AND p.USER_ID = s2.USER_ID
        WHERE
            p.PROCESS_ID = 'STEP3'
            AND p.EX_TIMESTAMP > s2.min_EX_TIMESTAMP
        GROUP BY
            p.SESSION_ID
          , p.USER_ID
    )
  , session4 AS (
        SELECT
            p.SESSION_ID
          , p.USER_ID
          , MIN(p.EX_TIMESTAMP) AS min_EX_TIMESTAMP
        FROM
            PROCESS_LOG p
            INNER JOIN session3 s3 ON p.SESSION_ID = s3.SESSION_ID
            AND p.USER_ID = s3.USER_ID
        WHERE
            p.PROCESS_ID = 'STEP4'
            AND p.EX_TIMESTAMP > s3.min_EX_TIMESTAMP
        GROUP BY
            p.SESSION_ID
          , p.USER_ID
    )
  , session5 AS (
        SELECT
            p.SESSION_ID
          , p.USER_ID
          , MIN(p.EX_TIMESTAMP) AS min_EX_TIMESTAMP
        FROM
            PROCESS_LOG p
            INNER JOIN session4 s4 ON p.SESSION_ID = s4.SESSION_ID
            AND p.USER_ID = s4.USER_ID
        WHERE
            p.PROCESS_ID = 'STEP5'
            AND p.EX_TIMESTAMP > s4.min_EX_TIMESTAMP
        GROUP BY
            p.SESSION_ID
          , p.USER_ID
    )
  , final_counts AS (
        SELECT
            'STEP1' AS PROCESS
          , COUNT(DISTINCT SESSION_ID) AS CNT
        FROM
            session1
        UNION ALL
        SELECT
            'STEP2'
          , COUNT(DISTINCT SESSION_ID)
        FROM
            session2
        UNION ALL
        SELECT
            'STEP3'
          , COUNT(DISTINCT SESSION_ID)
        FROM
            session3
        UNION ALL
        SELECT
            'STEP4'
          , COUNT(DISTINCT SESSION_ID)
        FROM
            session4
        UNION ALL
        SELECT
            'STEP5'
          , COUNT(DISTINCT SESSION_ID)
        FROM
            session5
    )
SELECT
    *
FROM
    final_counts
ORDER BY
    PROCESS;
提出情報
提出日時2023/12/17 06:30:07
コンテスト第10回 SQLコンテスト
問題顧客行動分析
受験者hiraku
状態 (詳細)WA
(Wrong Answer: 誤答)
メモリ使用量87 MB
メッセージ
テストケース(通過数/総数)
1/4
状態
メモリ使用量
データパターン1
WA
84 MB
データパターン2
WA
86 MB
データパターン3
WA
87 MB
データパターン4
AC
85 MB