ソースコード
WITH SAL_AMT_TABLE AS (
    SELECT ITEM_CODE, SUM(UNITPRICE * SALES_QTY) AS SAL_AMT
    FROM SALES
        INNER JOIN SALES_DTL
        ON SALES.SALES_NO = SALES_DTL.SALES_NO
    WHERE SALES_DATE BETWEEN "2023-06-01" AND "2023-06-30"
    GROUP BY ITEM_CODE
    ORDER BY SAL_AMT DESC, ITEM_CODE DESC
),
AMT_TABLE AS (
    SELECT A.ITEM_CODE AS ITEM_CODE,
        A.SAL_AMT AS SAL_AMT,
        SUM(B.SAL_AMT) AS CML_AMT
    FROM SAL_AMT_TABLE AS A
        INNER JOIN SAL_AMT_TABLE AS B
        ON A.SAL_AMT <= B.SAL_AMT
    GROUP BY A.ITEM_CODE
    ORDER BY SAL_AMT DESC, ITEM_CODE DESC
),
AMT_COMP_TABLE AS (
    SELECT ITEM_CODE,
        SAL_AMT,
        CML_AMT,
        ROUND(100.0 * SAL_AMT / SUM_AMT, 1) AS SAL_COMP,
        ROUND(100.0 * CML_AMT / SUM_AMT, 1) AS TTL_COMP
    FROM AMT_TABLE,
        (SELECT SUM(SAL_AMT) AS SUM_AMT FROM SAL_AMT_TABLE) AS S
)
SELECT ITEM.ITEM_CODE AS CODE,
    ITEM_NAME AS NAME,
    SAL_AMT,
    CML_AMT,
    SAL_COMP || "%" AS SAL_COMP,
    TTL_COMP || "%" AS TTL_COMP,
    CASE
        WHEN TTL_COMP <= 40.0 THEN "A"
        WHEN TTL_COMP <= 80.0 THEN "B"
        ELSE "C"
    END AS RANK
FROM ITEM
    INNER JOIN AMT_COMP_TABLE
    ON ITEM.ITEM_CODE = AMT_COMP_TABLE.ITEM_CODE



提出情報
提出日時2023/09/09 03:32:32
コンテスト第7回 SQLコンテスト
問題ABC分析
受験者Haar
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量77 MB
メッセージ
テストケース(通過数/総数)
3/3
状態
メモリ使用量
データパターン1
AC
76 MB
データパターン2
AC
77 MB
データパターン3
AC
76 MB