ソースコード
with item_sum as (
    select
        d.ITEM_CODE as CODE
      , i.ITEM_NAME as NAME
      , sum(d.UNITPRICE * d.SALES_QTY) as SAL_AMT
    from
               SALES     s
    inner join SALES_DTL d using(SALES_NO)
    inner join ITEM      i using(ITEM_CODE)
    where
        '2023-06-01' <= s.SALES_DATE and s.SALES_DATE <= '2023-06-30'
    group by
        d.ITEM_CODE
), total_sum as (
    select
        sum(SAL_AMT) as TOTAL_AMT
    from
        item_sum
), cum_sum as (
    select
        CODE
      , NAME
      , SAL_AMT
      , TOTAL_AMT
      , SUM(SAL_AMT) over(order by SAL_AMT desc) as CML_AMT
    from
        item_sum
      , total_sum
), proportion as (
    select
        CODE
      , NAME
      , SAL_AMT
      , CML_AMT
      , round((SAL_AMT * 100 * 1.00 / TOTAL_AMT * 1.00) , 2) as SAL_COMP
      , round((CML_AMT * 100 * 1.00 / TOTAL_AMT * 1.00) , 2) as TTL_COMP
    from
        cum_sum
)
select
    CODE
  , NAME
  , SAL_AMT
  , CML_AMT
  , format('%2.1f%', SAL_COMP) as SAL_COMP
  , format('%2.1f%', TTL_COMP) as TTL_COMP
  , case
        when TTL_COMP <= 40.0 then 'A'
        when TTL_COMP <= 80.0 then 'B'
        else                       'C'
    end as RANK
from
    proportion
order by
    3 desc
  , 1 desc
;
提出情報
提出日時2023/06/16 15:48:32
コンテスト第7回 SQLコンテスト
問題ABC分析
受験者kamaoda
状態 (詳細)WA
(Wrong Answer: 誤答)
メモリ使用量86 MB
メッセージ
テストケース(通過数/総数)
0/3
状態
メモリ使用量
データパターン1
WA
79 MB
データパターン2
WA
86 MB
データパターン3
WA
79 MB