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