ソースコード
with tmp as (
select
    sd.item_code
    ,i.item_name
    ,sum(sd.unitprice * sd.sales_qty) sum_amt
from
    sales_dtl sd 
    left join item i on sd.item_code = i.item_code
    left join sales s on sd.sales_no = s.sales_no
where
    s.sales_date between '2023-06-01' and '2023-06-30'
group by
    sd.item_code, i.item_name
), tmp2 as (
select
    item_code
    ,item_name
    ,sum_amt
    ,sum(sum_amt) over(order by sum_amt desc, item_code desc rows between unbounded preceding and current row) cml_amt
    ,sum(sum_amt) over(rows between unbounded preceding and unbounded following) all_amt
from
    tmp
), tmp3 as (
select
    item_code
    ,item_name
    ,sum_amt
    ,cml_amt
    ,case
        when lead(sum_amt, 1) over(order by sum_amt desc) = sum_amt then lead(cml_amt, 1) over(order by cml_amt)
        else cml_amt
    end as cml_amt2
    ,all_amt
from
    tmp2
), tmp4 as (
select
    item_code
    ,item_name
    ,sum_amt
    ,cml_amt
    ,round(((sum_amt * 1.0) / all_amt) * 100, 1) sal_comp
    ,round(((cml_amt2 * 1.0) / all_amt) * 100, 1) ttl_comp
from
    tmp3
), tmp5 as (
select
    item_code CODE
    ,item_name NAME
    ,sum_amt SAL_AMT
    ,cml_amt CML_AMT
    ,sal_comp || '%' SAL_COMP
    ,ttl_comp || '%' TTL_COMP
    ,case
        when ttl_comp < 40.0 then 'A'
        when ttl_comp < 80.0 then 'B'
        else 'C'
     end as RANK
from
    tmp4
)
select
    *
from
    tmp5
order by
    SAL_AMT desc, CODE desc
;
提出情報
提出日時2024/09/29 09:46:57
コンテスト第7回 SQLコンテスト
問題ABC分析
受験者nosh
状態 (詳細)WA
(Wrong Answer: 誤答)
メモリ使用量84 MB
メッセージ
テストケース(通過数/総数)
0/3
状態
メモリ使用量
データパターン1
WA
84 MB
データパターン2
WA
84 MB
データパターン3
WA
83 MB