ソースコード
with TMP as (
select
    I.ITEM_CODE as code
    ,item_name as name
    ,sum(unitprice * sales_qty) as sal_amt
from SALES S 
    inner join SALES_DTL SD
        on S.sales_no =SD.sales_no
    inner join ITEM I
        on SD.item_code = I.item_code
where
    sales_date between '2023-06-01' and '2023-06-30'
group by 1,2
)
,TMP2 as (
select 
    *
    , rank() over (partition by '' order by sal_amt desc) as RN 
    ,sum(sal_amt) over (partition by '') as total_sal
from TMP
order by 3 desc
)
,TMP3 as (
select
    T.CODE, T.NAME ,T.SAL_AMT
    ,1.0*T.sal_amt / T.total_sal as SAL_COMP
    ,sum(TT.sal_amt) as CML_AMT
    ,1.0*sum(TT.sal_amt)/T.total_sal as TTL_COMP
from
    TMP2 T
    left outer join
        TMP2 TT
        on 
            T.RN >= TT.RN
group by 1,2,3,4
)
select
    CODE
    ,NAME
    ,SAL_AMT
    ,CML_AMT
    ,case 
        when SAL_COMP=1 then '100%'
        when SAL_COMP>=0.1 then substr(round(SAL_COMP*100, 1) || '.0',1,4) || '%'  --
        else substr(round(SAL_COMP*100, 1) || '.0',1,3) || '%'  --
        end as SAL_COMP
    ,case 
        when TTL_COMP=1 then '100%'
        when TTL_COMP>=0.1 then substr(round(TTL_COMP*100, 1) || '.0',1,4) || '%'  --
        else substr(round(TTL_COMP*100, 1) || '.0',1,3) || '%'  --
        end as TTL_COMP
    ,case
        when TTL_COMP<=0.4 then 'A'
        when TTL_COMP<=0.8 then 'B'
        else 'C'
        end as RANK
from
    TMP3
order by SAL_AMT desc, CODE
;
提出情報
提出日時2023/06/18 15:20:26
コンテスト第7回 SQLコンテスト
問題ABC分析
受験者1120011
状態 (詳細)WA
(Wrong Answer: 誤答)
メモリ使用量91 MB
メッセージ
テストケース(通過数/総数)
0/3
状態
メモリ使用量
データパターン1
WA
86 MB
データパターン2
WA
91 MB
データパターン3
WA
90 MB