ソースコード
with target as (
select i.item_code as CODE,
item_name as NAME,
sum (d.UNITPRICE * d.SALES_QTY) as SAL_AMT
from sales s, SALES_DTL d, item i
where
 i.item_code=d.item_code 
and  d.SALES_NO=s.SALES_NO
and  s.SALES_DATE between '2023-06-01' and '2023-06-30'
group by CODE,NAME
),
all_amt as (
 select sum(SAL_AMT) all_amt from target
)
-- select all_amt from all_amt
select CODE,NAME,SAL_AMT,
SUM(SAL_AMT) OVER (ORDER BY SAL_AMT desc ) AS CML_AMT,
round(cast(SAL_AMT as REAL)/cast(all_amt as REAL)*100,1)||'%' as SAL_COMP,
round(cast(SUM(SAL_AMT) OVER (ORDER BY SAL_AMT desc ) as REAL)/cast(all_amt as REAL)*100,1)||'%' as TTL_COMP,
case 
 when cast(SUM(SAL_AMT) OVER (ORDER BY SAL_AMT desc ) as REAL)/cast(all_amt as REAL)*100 <= 40 then 'A'
 when cast(SUM(SAL_AMT) OVER (ORDER BY SAL_AMT desc ) as REAL)/cast(all_amt as REAL)*100 <= 80 then 'B'
 ELSE 'C'
end as RANK
from target,all_amt
order by SAL_AMT desc,CODE desc


提出情報
提出日時2023/06/16 17:00:57
コンテスト第7回 SQLコンテスト
問題ABC分析
受験者KT04
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量94 MB
メッセージ
テストケース(通過数/総数)
3/3
状態
メモリ使用量
データパターン1
AC
90 MB
データパターン2
AC
94 MB
データパターン3
AC
92 MB