ソースコード
select 
CODE
,NAME
,SAL_AMT
,CML_AMT
,SAL_COMP,
TTL_COMP_num||'%' as TTL_COMP
,case 
when TTL_COMP_num <= 40.0 then 'A'
when TTL_COMP_num <= 80.0 then 'B'
else 'C'
end as RANK
from(
select 
CODE
,NAME
,SAL_AMT
,CML_AMT
,SAL_COMP,
ROUND(cast(CML_AMT as real)/(select sum(SALES_AMT) from SALES WHERE SALES_DATE BETWEEN '2023-06-01' AND '2023-06-30') *100,1) as TTL_COMP_num
from(
select CODE
,NAME
,SAL_AMT
,CML_AMT
, ROUND((cast(SAL_AMT as REAL)/MAX(CML_AMT) OVER () *100),1)||'%' as SAL_COMP
from(
select CODE
,NAME
,SAL_AMT
,SUM(SAL_AMT) OVER (ORDER BY SAL_AMT desc) AS CML_AMT
from(
select it.ITEM_CODE as CODE
,it.ITEM_NAME as NAME
,sum(UNITPRICE * SALES_QTY) as SAL_AMT
from SALES_DTL as dt
inner join ITEM as it
on dt.ITEM_CODE = it.ITEM_CODE
inner join SALES as sa
on sa.SALES_NO = dt.SALES_NO
where SALES_DATE <= '2023-06-30' and SALES_DATE >= '2023-06-01'
group by CODE
order by SAL_AMT desc,CODE desc)
)))
提出情報
提出日時2024/11/11 20:09:04
コンテスト第7回 SQLコンテスト
問題ABC分析
受験者yoshino
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量85 MB
メッセージ
テストケース(通過数/総数)
3/3
状態
メモリ使用量
データパターン1
AC
84 MB
データパターン2
AC
85 MB
データパターン3
AC
84 MB