ソースコード
with amounts as (
    select
        pf_code,
        total_value as total_amounts
    from convenience
    where survey_year = '2019' and kind_code = '100'
),

shops as (
    select
        pf_code,
        total_value as total_shops
    from convenience
    where survey_year = '2019' and kind_code = '150'
),

pivot as (
    select
        a.pf_code,
        total_amounts,
        total_shops
    from amounts a
    join shops s using(pf_code)
),

grouped as (
    select
        row_number() over (order by total_amounts desc) as num,
        sum(total_amounts) over w as total_amounts,
        sum(total_shops) over w as total_shops
    from pivot
    window w as (order by total_amounts desc range between current row and 3 following)
),

grouped1 as (
select *
from grouped
where num % 3 = 1)

select
    total_amounts as TTL_SAL,
    round(cast(total_amounts as real) / cast(sum(total_amounts) over w2 as real), 2) as PER_SAL,
    round(cast(sum(total_amounts) over w1 as real) / cast(sum(total_amounts) over w2 as real), 2) as CUM_SAL,
    round(cast(total_amounts as real) / cast(total_shops as real), 0) as AVG_SAL
from grouped1
window w1 as (order by total_amounts desc range between unbounded preceding and current row),
w2 as (order by total_amounts desc range between unbounded preceding and unbounded following);
提出情報
提出日時2023/10/16 00:05:32
コンテスト第9回 SQLコンテスト
問題販売額分析
受験者kkurage
状態 (詳細)WA
(Wrong Answer: 誤答)
メモリ使用量82 MB
メッセージ
テストケース(通過数/総数)
0/3
状態
メモリ使用量
データパターン1
WA
82 MB
データパターン2
WA
77 MB
データパターン3
WA
77 MB