ソースコード
with base as (
select
    t1.PF_CODE
    , t1.TOTAL_VALUE as SALE
    , t2.TOTAL_VALUE as SHOP
from
    CONVENIENCE as t1
    inner join
    CONVENIENCE as t2
    on t1.PF_CODE=t2.PF_CODE
    and t1.KIND_CODE = 100
    and t2.KIND_CODE = 150
    and t1.SURVEY_YEAR = 2019
    and t2.SURVEY_YEAR = 2019
)
,base2 as (
select
    PF_CODE
    ,SALE
    ,SHOP
    ,(row_number() over (order by SALE desc,SHOP,PF_CODE)-1)/3+1 as NO
    ,sum(SALE) over () as TOTAL
from
    base
)
,base3 as (
select
    NO
    ,TOTAL
    ,sum(SALE) as TTL_SAL
    ,sum(SHOP) as SHOP
from
    base2
group by
    NO
    ,TOTAL
)
select
    NO
    ,TTL_SAL
    ,round(100.0*TTL_SAL/TOTAL,1) as PER_SAL
    ,round(100.0*sum(TTL_SAL) over(order by NO ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) /TOTAL,1) as CUM_SAL
    ,TTL_SAL/SHOP as AVG_SAL
from
    base3
order by
    NO
提出情報
提出日時2024/03/14 11:00:45
コンテスト第9回 SQLコンテスト
問題販売額分析
受験者gP2fWnUzTL
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量84 MB
メッセージ
テストケース(通過数/総数)
3/3
状態
メモリ使用量
データパターン1
AC
84 MB
データパターン2
AC
83 MB
データパターン3
AC
84 MB