ソースコード
WITH MEMBER AS
(
    SELECT
        COUNT(DISTINCT SESSION_ID) AS CNT
    FROM
        PURCHASE_HISTORY AS A

)
,ITEM_COMBI AS
(
    SELECT
         A.ITEM_CODE AS ITEM_A
        ,B.ITEM_CODE AS ITEM_B
        ,COUNT(*) AS CNT
    FROM
        PURCHASE_HISTORY AS A
        INNER JOIN
            PURCHASE_HISTORY AS B
            ON  B.SESSION_ID = A.SESSION_ID
            AND B.ITEM_CODE != A.ITEM_CODE
    GROUP BY
         ITEM_A
        ,ITEM_B
)
,ITEM AS
(
    SELECT
         A.ITEM_CODE
        ,COUNT(A.ITEM_CODE) AS CNT
    FROM
        PURCHASE_HISTORY AS A
    GROUP BY
        A.ITEM_CODE
)

SELECT
     ITEM_COMBI.ITEM_A
    ,ITEM_COMBI.ITEM_B
    ,ROUND(ITEM_COMBI.CNT * 100.0 / MEMBER.CNT, 5) AS SUPPORT
    ,ROUND(ITEM_COMBI.CNT * 100.0 / ITEM_A.CNT, 5) AS CONFIDENCE
    ,ROUND((ITEM_COMBI.CNT * 1.0 / ITEM_A.CNT) / (ITEM_B.CNT * 1.0 / MEMBER.CNT), 5) AS LIFT
FROM
    ITEM_COMBI, MEMBER
    INNER JOIN
        ITEM AS ITEM_A
        ON  ITEM_A.ITEM_CODE = ITEM_COMBI.ITEM_A
    INNER JOIN
        ITEM AS ITEM_B
        ON  ITEM_B.ITEM_CODE = ITEM_COMBI.ITEM_B
ORDER BY
     LIFT DESC
    ,SUPPORT DESC
    ,CONFIDENCE DESC
    ,ITEM_A DESC
提出情報
提出日時2024/02/29 23:19:31
コンテスト第11回 SQLコンテスト
問題アソシエーション分析
受験者mo
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量84 MB
メッセージ
テストケース(通過数/総数)
3/3
状態
メモリ使用量
データパターン1
AC
83 MB
データパターン2
AC
84 MB
データパターン3
AC
84 MB