ソースコード
WITH T0 AS (
    SELECT
        ITEM_CODE AS ITEM,
        COUNT(DISTINCT(MEMBER_CODE)) AS CNT
    FROM
        PURCHASE_HISTORY
    GROUP BY
        ITEM_CODE
),
T1 AS (
    SELECT 
        PA.ITEM_CODE AS ITEM_A,
        PB.ITEM_CODE AS ITEM_B,
        COUNT(DISTINCT(PA.MEMBER_CODE)) AS CNT
    FROM
        PURCHASE_HISTORY AS PA
    INNER JOIN
        PURCHASE_HISTORY AS PB
    ON
        PA.ITEM_CODE != PB.ITEM_CODE AND
        PA.MEMBER_CODE = PB.MEMBER_CODE
    GROUP BY
        ITEM_A,
        ITEM_B
)
SELECT
    ITEM_A,
    ITEM_B,
    ROUND(
        T1.CNT
        * 100.0
        / (SELECT COUNT(DISTINCT(MEMBER_CODE)) FROM PURCHASE_HISTORY)
    , 5) AS 'SUPPORT',
    ROUND(
        T1.CNT
        * 100.0
        / TA.CNT
    , 5) AS 'CONFIDENCE',
    ROUND(
        T1.CNT
        * 1.0
        / TA.CNT
        / TB.CNT
        * (SELECT COUNT(DISTINCT(MEMBER_CODE)) FROM PURCHASE_HISTORY)
    , 5) AS 'LIFT'
FROM
    T1
INNER JOIN
    T0 AS TA
ON
    T1.ITEM_A = TA.ITEM
INNER JOIN
    T0 AS TB
ON
    T1.ITEM_B = TB.ITEM
ORDER BY
    5 DESC,
    3 DESC,
    4 DESC,
    1 DESC
提出情報
提出日時2024/02/19 11:34:09
コンテスト第11回 SQLコンテスト
問題アソシエーション分析
受験者tabr
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量97 MB
メッセージ
テストケース(通過数/総数)
3/3
状態
メモリ使用量
データパターン1
AC
85 MB
データパターン2
AC
97 MB
データパターン3
AC
87 MB