ソースコード
WITH SUB1 AS (
    SELECT I.ITEM_CODE AS CODE , I.ITEM_NAME AS NAME,
    SUM(SD.UNITPRICE * SD.SALES_QTY) AS SAL_AMT
    FROM ITEM I JOIN SALES_DTL SD ON I.ITEM_CODE = SD.ITEM_CODE
    JOIN SALES S ON SD.SALES_NO = S.SALES_NO
    WHERE S.SALES_DATE BETWEEN '2023-06-01' AND '2023-06-30'
    GROUP BY I.ITEM_CODE
    ORDER BY SAL_AMT DESC, CODE DESC
), SUB2 AS (
    SELECT SUM(SAL_AMT) AS SUM_SAL_AMT FROM SUB1
), SUB3 AS (
    SELECT CODE, NAME, SAL_AMT,
    (SELECT SUM(SAL_AMT) FROM SUB1 A WHERE A.SAL_AMT >= SUB1.SAL_AMT) AS CML_AMT,
    ROUND(CAST(SAL_AMT AS REAL) / (SELECT SUM_SAL_AMT FROM SUB2) * 100, 1)
    AS SAL_COMP,
    ROUND(CAST((SELECT SUM(SAL_AMT) FROM SUB1 A WHERE A.SAL_AMT >= SUB1.SAL_AMT)
    AS REAL) / (SELECT SUM_SAL_AMT FROM SUB2) * 100, 1) AS TTL_COMP
    FROM SUB1
)

SELECT CODE, NAME, SAL_AMT, CML_AMT, SAL_COMP || '%' AS SAL_COMP,
ROUND(CAST(CML_AMT AS REAL) / (SELECT SUM_SAL_AMT FROM SUB2) * 100, 1) || '%'
AS TTL_COMP, CASE WHEN TTL_COMP <= 40 THEN 'A' WHEN TTL_COMP <= 80 THEN 'B'
ELSE 'C' END AS RANK
FROM SUB3;
提出情報
提出日時2023/06/21 23:27:47
コンテスト第7回 SQLコンテスト
問題ABC分析
受験者roaris
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量77 MB
メッセージ
テストケース(通過数/総数)
3/3
状態
メモリ使用量
データパターン1
AC
76 MB
データパターン2
AC
76 MB
データパターン3
AC
77 MB