ソースコード
with tmp as(
select
    sa.item_code as CODE
    ,it.item_name as NAME
    ,sum(sa.unitprice * sa.SALES_QTY) as SAL_AMT
from sales_dtl as sa
inner join sales as sal
on sa.sales_no = sal.sales_no
inner join item as it
on sa.item_code = it.item_code
    
where
    sal.sales_date between date('2023-06-01') and date('2023-06-30')
group by
    CODE,NAME
)
select
    CODE
    ,NAME
    ,SAL_AMT
    ,sum(SAL_AMT) over (order by SAL_AMT desc) AS CML_AMT
    ,round(cast(SAL_AMT as double) / (select sum(sal_amt) from tmp) *100,1) || '%' as SAL_COMP
    ,round(cast(sum(SAL_AMT) over (order by SAL_AMT desc) as REAL) / (select sum(sal_amt) from tmp) *100,1) || '%' as TTL_COMP
    ,CASE
        WHEN round(cast(sum(SAL_AMT) over (order by SAL_AMT desc) as REAL) / (select sum(sal_amt) from tmp) *100,1) <= 40 THEN 'A'
        WHEN round(cast(sum(SAL_AMT) over (order by SAL_AMT desc) as REAL) / (select sum(sal_amt) from tmp) *100,1) <= 80 THEN 'B'
        ELSE 'C'
        END AS RANK
from tmp
order by 
    SAL_AMT desc
    ,CODE desc
提出情報
提出日時2023/08/02 17:01:11
コンテスト第7回 SQLコンテスト
問題ABC分析
受験者mywk
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量87 MB
メッセージ
テストケース(通過数/総数)
3/3
状態
メモリ使用量
データパターン1
AC
86 MB
データパターン2
AC
78 MB
データパターン3
AC
87 MB