ソースコード


with tmp as
(
select sum(UNITPRICE * SALES_QTY) SAL_AMT,
item.ITEM_CODE
from sales inner join sales_dtl on sales.sales_no=sales_dtl.sales_no
inner join item on item.item_code=sales_dtl.item_code
where SALES_DATE between '2023-06-01' and '2023-06-30'
group by 2 order by 1 desc
),
 tmp2 as
(select sum(SAL_AMT) as totals from tmp),
 tmp3 as
(
select ITEM_CODE,SAL_AMT, round(100.0*SAL_AMT/totals,1) as SAL_COMP
from tmp , tmp2
),
tmp4 as (
select ITEM_CODE,SAL_AMT,
sum(SAL_AMT) over ( order by SAL_COMP desc,SAL_AMT desc ROWS UNBOUNDED PRECEDING) as CML_AMT ,
SAL_COMP  as SAL_COMP,
sum(SAL_COMP) over ( order by SAL_COMP desc,SAL_AMT desc ROWS UNBOUNDED PRECEDING)  as TTL_COMP 
from tmp3
)
select 
tmp4.ITEM_CODE as CODE,item_name as NAME,SAL_AMT,CML_AMT,SAL_COMP||'%' as 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 tmp4
inner join 
item
on tmp4.item_code=item.item_code
order by 
SAL_AMT desc,tmp4.ITEM_CODE desc

提出情報
提出日時2023/06/18 21:56:44
コンテスト第7回 SQLコンテスト
問題ABC分析
受験者noneof383
状態 (詳細)WA
(Wrong Answer: 誤答)
メモリ使用量95 MB
メッセージ
テストケース(通過数/総数)
0/3
状態
メモリ使用量
データパターン1
WA
78 MB
データパターン2
WA
88 MB
データパターン3
WA
95 MB