ソースコード
with ttl as (
    select 
    sum(sales_amt) as ttl
    from sales where sales_date between '2023-06-01' and '2023-06-30'
)
select
a1.item_code as CODE
,a1.item_name as NAME
,t1.total_amt as SAL_AMT
,t1.cml as CML_AMT
,round(100.0*t1.total_amt/ttl,1)||'%' as SAL_COMP
,round(100.0*t1.cml/ttl,1)||'%' as TTL_COMP
,case
    when round(100.0*t1.cml/ttl,1) <= 40 then 'A'
    when round(100.0*t1.cml/ttl,1) <= 80 then 'B'
    else 'C'
end as RANK
from item as a1
inner join(
    select
    a.item_code as item
    ,t.total_amt
    ,sum(total_amt) over (order by total_amt desc) as cml
    from item as a
    inner join (
        select
        sd.item_code as item
        ,sum(unitprice*delivered_qty) as total_amt
        from sales as s
        inner join sales_dtl as sd
        on s.sales_no=sd.sales_no
        where sales_date between '2023-06-01' and '2023-06-30'
        group by sd.item_code
        order by total_amt desc,sd.item_code desc
    ) as t
    on t.item=a.item_code
    order by total_amt desc
) as t1
on t1.item=a1.item_code
cross join ttl
order by SAL_AMT desc,item_code desc
提出情報
提出日時2024/05/30 11:50:15
コンテスト第7回 SQLコンテスト
問題ABC分析
受験者HamamatsuUnagi
状態 (詳細)WA
(Wrong Answer: 誤答)
メモリ使用量85 MB
メッセージ
テストケース(通過数/総数)
1/3
状態
メモリ使用量
データパターン1
AC
85 MB
データパターン2
WA
85 MB
データパターン3
WA
85 MB