ソースコード
WITH t1 AS (SELECT DISTINCT a.item_code a
                          , b.item_code b
                          , COUNT(DISTINCT pua.SESSION_ID) cnt
            FROM PURCHASE_HISTORY a
               , PURCHASE_HISTORY b
                 JOIN PURCHASE_HISTORY pua ON pua.ITEM_CODE = a.ITEM_CODE
                 JOIN PURCHASE_HISTORY pub ON pub.ITEM_CODE = b.ITEM_CODE AND pua.SESSION_ID = pub.SESSION_ID

            WHERE a.ITEM_CODE <> b.ITEM_CODE
            GROUP BY a.item_code, b.item_code)
   , t2 AS (SELECT item_code, COUNT(*) cnt
            FROM PURCHASE_HISTORY pu
            GROUP BY pu.item_code)

SELECT a ITEM_A
     , b ITEM_B
     , ROUND(x * 100, 5) SUPPORT
     , ROUND(y * 100, 5) CONFIDENCE
     , ROUND(y / z, 5) LIFT
FROM (SELECT t1.a
           , t1.b
           , CAST(IFNULL(t1.cnt, 0) AS real) / (SELECT COUNT(DISTINCT session_id) FROM PURCHASE_HISTORY) x
           , CAST(IFNULL(t1.cnt, 0) AS real) / ac.cnt y
           , CAST(IFNULL(bc.cnt, 0) AS real) / (SELECT COUNT(DISTINCT session_id) FROM PURCHASE_HISTORY) z
      FROM t1
           LEFT JOIN t2 ac ON t1.a = ac.ITEM_CODE
           LEFT JOIN t2 bc ON t1.b = bc.ITEM_CODE)
ORDER BY 5 DESC, 3 DESC, 4 DESC, 1 DESC;
提出情報
提出日時2024/06/19 15:14:30
コンテスト第11回 SQLコンテスト
問題アソシエーション分析
受験者pp1mqa6hkm
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量85 MB
メッセージ
テストケース(通過数/総数)
3/3
状態
メモリ使用量
データパターン1
AC
84 MB
データパターン2
AC
85 MB
データパターン3
AC
84 MB