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