ソースコード
SELECT
    PROCESS_ID AS PROCESS,
    COUNT(SESSION_ID) AS CNT
FROM
    PROCESS_LOG
WHERE
    PROCESS_ID = "STEP1"
GROUP BY
    PROCESS_ID
UNION ALL
    SELECT
        MAIN.PROCESS_ID AS PROCESS,
        COUNT(MAIN.SESSION_ID) AS CNT
    FROM
        PROCESS_LOG MAIN
    WHERE
        MAIN.PROCESS_ID = "STEP2"
        AND EXISTS (
            SELECT
                1
            FROM
                PROCESS_LOG SUB
            WHERE
                SUB.SESSION_ID = MAIN.SESSION_ID
                AND PROCESS_ID = "STEP1"
                AND SUB.EX_TIMESTAMP < MAIN.EX_TIMESTAMP
        )
    GROUP BY
        MAIN.PROCESS_ID
UNION ALL 
    SELECT
        MAIN.PROCESS_ID AS PROCESS,
        COUNT(MAIN.SESSION_ID) AS CNT
    FROM
        PROCESS_LOG MAIN
    WHERE
        MAIN.PROCESS_ID = "STEP3"
        AND EXISTS (
            SELECT
                1
            FROM
                PROCESS_LOG SUB
            WHERE
                SUB.SESSION_ID = MAIN.SESSION_ID
                AND PROCESS_ID = "STEP1"
                AND SUB.EX_TIMESTAMP < MAIN.EX_TIMESTAMP
        )
        AND EXISTS (
            SELECT
                1
            FROM
                PROCESS_LOG SUB
            WHERE
                SUB.SESSION_ID = MAIN.SESSION_ID
                AND PROCESS_ID = "STEP2"
                AND SUB.EX_TIMESTAMP < MAIN.EX_TIMESTAMP
        )
    GROUP BY
        MAIN.PROCESS_ID
UNION ALL
    SELECT
        MAIN.PROCESS_ID AS PROCESS,
        COUNT(MAIN.SESSION_ID) AS CNT
    FROM
        PROCESS_LOG MAIN
    WHERE
        MAIN.PROCESS_ID = "STEP4"
        AND EXISTS (
            SELECT
                1
            FROM
                PROCESS_LOG SUB
            WHERE
                SUB.SESSION_ID = MAIN.SESSION_ID
                AND PROCESS_ID = "STEP1"
                AND SUB.EX_TIMESTAMP < MAIN.EX_TIMESTAMP
        )
        AND EXISTS (
            SELECT
                1
            FROM
                PROCESS_LOG SUB
            WHERE
                SUB.SESSION_ID = MAIN.SESSION_ID
                AND PROCESS_ID = "STEP2"
                AND SUB.EX_TIMESTAMP < MAIN.EX_TIMESTAMP
        )
        AND EXISTS (
            SELECT
                1
            FROM
                PROCESS_LOG SUB
            WHERE
                SUB.SESSION_ID = MAIN.SESSION_ID
                AND PROCESS_ID = "STEP3"
                AND SUB.EX_TIMESTAMP < MAIN.EX_TIMESTAMP
                AND EXISTS (
                    SELECT
                        1
                    FROM
                        PROCESS_LOG SUB_2
                    WHERE
                        SUB_2.SESSION_ID = SUB.SESSION_ID
                        AND PROCESS_ID = "STEP2"
                        AND SUB_2.EX_TIMESTAMP < SUB.EX_TIMESTAMP
                )
        )
    GROUP BY
        MAIN.PROCESS_ID
UNION ALL
    SELECT
        MAIN.PROCESS_ID AS PROCESS,
        COUNT(MAIN.SESSION_ID) AS CNT
    FROM
        PROCESS_LOG MAIN
    WHERE
        MAIN.PROCESS_ID = "STEP5"
        AND EXISTS (
            SELECT
                1
            FROM
                PROCESS_LOG SUB
            WHERE
                SUB.SESSION_ID = MAIN.SESSION_ID
                AND PROCESS_ID = "STEP1"
                AND SUB.EX_TIMESTAMP < MAIN.EX_TIMESTAMP
        )
        AND EXISTS (
            SELECT
                1
            FROM
                PROCESS_LOG SUB
            WHERE
                SUB.SESSION_ID = MAIN.SESSION_ID
                AND PROCESS_ID = "STEP2"
                AND SUB.EX_TIMESTAMP < MAIN.EX_TIMESTAMP
        )
        AND EXISTS (
            SELECT
                1
            FROM
                PROCESS_LOG SUB
            WHERE
                SUB.SESSION_ID = MAIN.SESSION_ID
                AND PROCESS_ID = "STEP3"
                AND SUB.EX_TIMESTAMP < MAIN.EX_TIMESTAMP
                AND EXISTS (
                    SELECT
                        1
                    FROM
                        PROCESS_LOG SUB_2
                    WHERE
                        SUB_2.SESSION_ID = SUB.SESSION_ID
                        AND PROCESS_ID = "STEP2"
                        AND SUB_2.EX_TIMESTAMP < SUB.EX_TIMESTAMP
                )
        )
        AND EXISTS (
            SELECT
                1
            FROM
                PROCESS_LOG SUB
            WHERE
                SUB.SESSION_ID = MAIN.SESSION_ID
                AND PROCESS_ID = "STEP4"
                AND SUB.EX_TIMESTAMP < MAIN.EX_TIMESTAMP
                AND EXISTS (
                    SELECT
                        1
                    FROM
                        PROCESS_LOG SUB_2
                    WHERE
                        SUB_2.SESSION_ID = SUB.SESSION_ID
                        AND PROCESS_ID = "STEP3"
                        AND SUB_2.EX_TIMESTAMP < SUB.EX_TIMESTAMP
                        AND EXISTS (
                            SELECT
                                1
                            FROM
                                PROCESS_LOG SUB_3
                            WHERE
                                SUB_3.SESSION_ID = SUB_2.SESSION_ID
                                AND PROCESS_ID = "STEP2"
                                AND SUB_3.EX_TIMESTAMP < SUB_2.EX_TIMESTAMP
                        )
                )
        )
    GROUP BY
        MAIN.PROCESS_ID
ORDER BY
    PROCESS;
提出情報
提出日時2023/12/17 17:30:27
コンテスト第10回 SQLコンテスト
問題顧客行動分析
受験者g_i_f_u
状態 (詳細)WA
(Wrong Answer: 誤答)
メモリ使用量88 MB
メッセージ
テストケース(通過数/総数)
0/4
状態
メモリ使用量
データパターン1
WA
87 MB
データパターン2
WA
88 MB
データパターン3
WA
86 MB
データパターン4
WA
85 MB