ソースコード
with base as (
select ITEM_CODE, 
sum(SALES_QTY * UNITPRICE ) as AMT,
rank()over(order by sum(SALES_QTY * UNITPRICE ) desc) as rnk
from SALES
join SALES_DTL
on   SALES.SALES_NO = SALES_DTL.SALES_NO
where SALES.SALES_DATE between '2023-06-01' and '2023-06-30'
group by ITEM_CODE
)
select main.ITEM_CODE as CODE,
(select ITEM_NAME from ITEM where ITEM_CODE = main.ITEM_CODE) as NAME,
main.AMT as SAL_AMT,
(select sum(AMT) from base where rnk <= main.rnk) as CML_AMT,
round(cast (main.AMT as real) *100 / (select sum(AMT) from base) , 1) || '%' as SAL_COMP,
round(cast ((select sum(AMT) from base where rnk <= main.rnk) as real) *100 / (select sum(AMT) from base) , 1) || '%' as TTL_COMP,
case 
when round(cast ((select sum(AMT) from base where rnk <= main.rnk) as real) *100 / (select sum(AMT) from base) , 1)  <= 40 then 'A'
when round(cast ((select sum(AMT) from base where rnk <= main.rnk) as real) *100 / (select sum(AMT) from base) , 1)  <= 80 then 'B'
else 'C' end as RANK
from base main
提出情報
提出日時2024/04/28 20:01:33
コンテスト第7回 SQLコンテスト
問題ABC分析
受験者yunyun8686
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量85 MB
メッセージ
テストケース(通過数/総数)
3/3
状態
メモリ使用量
データパターン1
AC
84 MB
データパターン2
AC
85 MB
データパターン3
AC
85 MB