ソースコード
-- ITEM_A
-- ITEM_B
-- SUPPORT
-- CONFIDENCE
-- LIFT

SELECT 
    ITEM_A,
    ITEM_B,
    CAST(COUNT(DISTINCT MEMBER_CODE) AS FLOAT) / (SELECT COUNT(DISTINCT MEMBER_CODE) FROM PURCHASE_HISTORY) * 100 AS SUPPORT,
    CAST(COUNT(DISTINCT MEMBER_CODE) AS FLOAT) / (SELECT COUNT(DISTINCT MEMBER_CODE) FROM PURCHASE_HISTORY WHERE ITEM_CODE = ITEM_A) * 100 AS CONFIDENCE,
    -- (SELECT COUNT(DISTINCT MEMBER_CODE) FROM PURCHASE_HISTORY WHERE ITEM_CODE = ITEM_B) AS uu_b,
    -- CAST((SELECT COUNT(DISTINCT MEMBER_CODE) FROM PURCHASE_HISTORY WHERE ITEM_CODE = ITEM_B) AS FLOAT) / (SELECT COUNT(DISTINCT MEMBER_CODE) FROM PURCHASE_HISTORY) * 100 AS uu_bb,
    CAST(COUNT(DISTINCT MEMBER_CODE) AS FLOAT) / (SELECT COUNT(DISTINCT MEMBER_CODE) FROM PURCHASE_HISTORY WHERE ITEM_CODE = ITEM_A) / (CAST((SELECT COUNT(DISTINCT MEMBER_CODE) FROM PURCHASE_HISTORY WHERE ITEM_CODE = ITEM_B) AS FLOAT) / (SELECT COUNT(DISTINCT MEMBER_CODE) FROM PURCHASE_HISTORY)) AS LIFT
FROM (
    SELECT 
        ITEM_A.MEMBER_CODE,
        ITEM_A.ITEM_CODE AS ITEM_A,
        ITEM_B.ITEM_CODE AS ITEM_B
    FROM (
        SELECT 
            MEMBER_CODE,
            ITEM_CODE
        FROM
            PURCHASE_HISTORY
    ) AS ITEM_A
    INNER JOIN (
        SELECT 
            MEMBER_CODE,
            ITEM_CODE
        FROM
            PURCHASE_HISTORY
    ) AS ITEM_B
    ON
        ITEM_A.MEMBER_CODE = ITEM_B.MEMBER_CODE
        AND ITEM_A.ITEM_CODE != ITEM_B.ITEM_CODE
)
GROUP BY 
    ITEM_A,
    ITEM_B
ORDER BY 
    LIFT DESC,
    SUPPORT DESC,
    CONFIDENCE DESC,
    ITEM_A DESC
-- 算出したリフト値の降順
-- 算出した支持度の降順
-- 算出した信頼度値の降順
-- 商品Aの商品コードの降順
提出情報
提出日時2024/02/16 15:38:58
コンテスト第11回 SQLコンテスト
問題アソシエーション分析
受験者muddydixon
状態 (詳細)WA
(Wrong Answer: 誤答)
メモリ使用量85 MB
メッセージ
テストケース(通過数/総数)
0/3
状態
メモリ使用量
データパターン1
WA
85 MB
データパターン2
WA
85 MB
データパターン3
WA
85 MB