ソースコード
with total_sales as (
    select sum(sales_amt) as total_amt
    from sales
    where sales_date between '2023-06-01' and '2023-06-30'
),
sum_item as(
    select sd.item_code, sum(sd.unitprice*sd.sales_qty) as amt
    from sales s
    inner join sales_dtl as sd on s.sales_no=sd.sales_no
    where s.sales_date between '2023-06-01' and '2023-06-30'
    group by sd.item_code
),
cumul_sales as (
    select item_code, amt, sum(amt) over (order by (amt) desc) as cumul_amt
    from sum_item
)
select 
    cs.item_code as CODE
    , item_name as NAME
    , cs.amt as SAL_AMT
    , cs.cumul_amt as CML_AMT
    , round((cast(cs.amt as real)/ts.total_amt * 100),1)||'%' as SAL_COMP
    , round((cast(cs.cumul_amt as real)/ts.total_amt * 100),1)||'%' as TTL_COMP
    , case 
        when round((cast(cs.cumul_amt as real)/ts.total_amt * 100),1)<=40 then 'A'
        when round((cast(cs.cumul_amt as real)/ts.total_amt * 100),1)<=80 then 'B'
        ELSE 'C'
        end as RANK
from cumul_sales as cs
cross join total_sales as ts
inner join item on item.item_code=cs.item_code
order by 3 desc, 1 desc;
提出情報
提出日時2024/05/09 11:29:15
コンテスト第7回 SQLコンテスト
問題ABC分析
受験者sjty9561
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量85 MB
メッセージ
テストケース(通過数/総数)
3/3
状態
メモリ使用量
データパターン1
AC
85 MB
データパターン2
AC
85 MB
データパターン3
AC
85 MB