ソースコード
with sa as (
    select 
        pf_code,
        sum(total_value) as sales,
        sum(total_value) over() as sumtotal
    from convenience
    where survey_year='2019' and kind_code='100'
    group by pf_code
),
cnt as (
    select 
        pf_code,
        sum(total_value) as count
    from convenience
    where survey_year='2019' and kind_code='150'
    group by pf_code
),
tmp as (
    select
        row_number() over(order by sales desc,count,sa.pf_code) as ranking,
        sa.pf_code as code,
        sales,
        count,
        sumtotal
    from sa
    inner join cnt
    on sa.pf_code=cnt.pf_code
),
sumtbl as (
    select
        ranking,
        sum(sales) over(order by ranking rows 2 preceding) as TTL_SAL,
        sum(sales) over(order by ranking) as subtotal,
        sumtotal,
        sum(count) over(order by ranking rows 2 preceding) as gsum_shop
    from tmp
)
select 
    ranking/3 as NO,
    TTL_SAL,
    round(cast(TTL_SAL as real)/cast(sumtotal as real)*100,1) as PER_SAL,
    round(cast(subtotal as real)/cast(sumtotal as real)*100,1) as CUM_SAL,
    cast(TTL_SAL/gsum_shop as int) as AVG_SAL
from sumtbl
where ranking%3=0
order by NO;
提出情報
提出日時2024/06/23 21:35:20
コンテスト第9回 SQLコンテスト
問題販売額分析
受験者kate
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量92 MB
メッセージ
テストケース(通過数/総数)
3/3
状態
メモリ使用量
データパターン1
AC
92 MB
データパターン2
AC
90 MB
データパターン3
AC
92 MB