ソースコード
WITH sales_summary AS (
    SELECT 
        ITEM.ITEM_CODE AS CODE,
        ITEM.ITEM_NAME AS NAME,
        SUM(SALES_DTL.UNITPRICE * SALES_DTL.SALES_QTY) AS SAL_AMT
    FROM
        SALES
    JOIN
        SALES_DTL ON SALES.SALES_NO = SALES_DTL.SALES_NO
    JOIN
        ITEM ON SALES_DTL.ITEM_CODE = ITEM.ITEM_CODE
    WHERE
        SALES.SALES_DATE BETWEEN '2023-06-01' AND '2023-06-30'
    GROUP BY
        ITEM.ITEM_CODE, ITEM.ITEM_NAME
    ORDER BY
        SAL_AMT DESC
)
SELECT
    CODE,
    NAME,
    SAL_AMT,
    SUM(SAL_AMT) OVER (ORDER BY SAL_AMT DESC) AS CML_AMT,
    ROUND(SAL_AMT*100.0 / SUM(SAL_AMT) OVER (), 1) || '%' AS SAL_COMP,
    ROUND(SUM(SAL_AMT) OVER (ORDER BY SAL_AMT DESC)*100.0 / SUM(SAL_AMT) OVER (), 1) || '%' AS TTL_COMP,
    CASE
        WHEN ROUND(SUM(SAL_AMT) OVER (ORDER BY SAL_AMT DESC)*100.0 / SUM(SAL_AMT) OVER (), 1) <= 40 THEN 'A'
        WHEN ROUND(SUM(SAL_AMT) OVER (ORDER BY SAL_AMT DESC)*100.0 / SUM(SAL_AMT) OVER (), 1) <= 80 THEN 'B'
        ELSE 'C'
    END AS RANK
FROM
    sales_summary
ORDER BY
    SAL_AMT DESC,
    CODE DESC
提出情報
提出日時2023/06/18 01:02:15
コンテスト第7回 SQLコンテスト
問題ABC分析
受験者hogehoge
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量79 MB
メッセージ
テストケース(通過数/総数)
3/3
状態
メモリ使用量
データパターン1
AC
79 MB
データパターン2
AC
79 MB
データパターン3
AC
79 MB