ソースコード
WITH T1 AS(
    SELECT
        COUNT(DISTINCT SESSION_ID) AS CNT_ALL
    FROM
        PURCHASE_HISTORY
), T2 AS(
    SELECT
        *,
        COUNT(DISTINCT SESSION_ID) AS CNT_A
    FROM
        PURCHASE_HISTORY
    GROUP BY
        ITEM_CODE
), T3 AS(
    SELECT
        P1.ITEM_CODE AS ITEM_A,
        P2.ITEM_CODE AS ITEM_B,
        COUNT(*) AS CNT_AB
    FROM
        PURCHASE_HISTORY AS P1
    CROSS JOIN
        PURCHASE_HISTORY AS P2
    WHERE
        P1.SESSION_ID = P2.SESSION_ID
    GROUP BY
        P1.ITEM_CODE,
        P2.ITEM_CODE
), T4 AS(
    SELECT
        ITEM_A,
        ITEM_B,
        CNT_AB,
        TA.CNT_A AS CNT_A,
        TB.CNT_A AS CNT_B
    FROM
        T3
    INNER JOIN
        T2 AS TA ON ITEM_A = TA.ITEM_CODE,
        T2 AS TB ON ITEM_B = TB.ITEM_CODE
    WHERE
        ITEM_A != ITEM_B
), T5 AS(
    SELECT
        *
    FROM T4
    CROSS JOIN
        T1
), T6 AS(
    SELECT
        ITEM_A,
        ITEM_B,
        ROUND(100.0 * CNT_AB / CNT_ALL, 5) AS SUPPORT,
        ROUND(100.0 * CNT_AB / CNT_A, 5) AS CONFIDENCE,
        ROUND(1.0 * CNT_AB * CNT_ALL / (1.0 * CNT_A * CNT_B), 5) AS LIFT
    FROM
        T5
    ORDER BY
        LIFT DESC,
        SUPPORT DESC,
        CONFIDENCE DESC,
        ITEM_A DESC
)
SELECT
    *
    FROM T6
提出情報
提出日時2024/02/19 11:46:49
コンテスト第11回 SQLコンテスト
問題アソシエーション分析
受験者tokusakurai
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量101 MB
メッセージ
テストケース(通過数/総数)
3/3
状態
メモリ使用量
データパターン1
AC
90 MB
データパターン2
AC
91 MB
データパターン3
AC
101 MB