ソースコード
WITH T0 AS(
    SELECT
        COUNT(DISTINCT SESSION_ID) AS AMT
    FROM
        PURCHASE_HISTORY
), T1 AS(
    SELECT
        ITEM_CODE,
        COUNT(DISTINCT SESSION_ID) AS AMT
    FROM
        PURCHASE_HISTORY
    GROUP BY
        ITEM_CODE
), T2 AS(
    SELECT
        T_A.ITEM_CODE AS ITEM_A,
        T_B.ITEM_CODE AS ITEM_B,
        COUNT(DISTINCT T_A.SESSION_ID) AS AMT
    FROM
        PURCHASE_HISTORY AS T_A
    CROSS JOIN
        PURCHASE_HISTORY AS T_B
    WHERE
        ITEM_A != ITEM_B
        AND T_A.SESSION_ID = T_B.SESSION_ID
    GROUP BY
        ITEM_A,
        ITEM_B
), T3 AS(
    SELECT
        T1_A.ITEM_CODE AS ITEM_A,
        T1_B.ITEM_CODE AS ITEM_B,
        T1_A.AMT AS AMT_A,
        T1_B.AMT AS AMT_B
    FROM
        T1 AS T1_A
    CROSS JOIN
        T1 AS T1_B
), T4 AS(
    SELECT
        T3.ITEM_A,
        T3.ITEM_B,
        T0.AMT AS AMT,
        T3.AMT_A AS AMT_A,
        T3.AMT_B AS AMT_B,
        CASE
            WHEN T2.AMT IS NULL THEN 0
            ELSE T2.AMT
        END AS AMT_AB
    FROM
        T3
    CROSS JOIN
        T0
    INNER JOIN
        T2 ON
            T2.ITEM_A = T3.ITEM_A
            AND T2.ITEM_B = T3.ITEM_B
), T5 AS(
    SELECT
        ITEM_A,
        ITEM_B,
        ROUND(
            100.0 * AMT_AB / AMT, 5
        ) AS SUPPORT,
        ROUND(
            100.0 * AMT_AB / AMT_A, 5
        ) AS CONFIDENCE,
        ROUND(
            (1.0 * AMT_AB / AMT_A) / (1.0 * AMT_B / AMT), 5
        ) AS LIFT
    FROM
        T4
    WHERE
        AMT_AB > 0
    ORDER BY
        LIFT DESC,
        SUPPORT DESC,
        CONFIDENCE DESC,
        ITEM_A ASC
)
SELECT
    *
    FROM
        T5
提出情報
提出日時2024/04/20 18:52:31
コンテスト第11回 SQLコンテスト
問題アソシエーション分析
受験者tokusakurai
状態 (詳細)WA
(Wrong Answer: 誤答)
メモリ使用量86 MB
メッセージ
テストケース(通過数/総数)
1/3
状態
メモリ使用量
データパターン1
AC
86 MB
データパターン2
WA
85 MB
データパターン3
WA
86 MB