ソースコード
select 
    CODE
    , NAME
    , sum(case when year=2022 then rank end) as '2022_RANK'
    , sum(case when year=2022 then ratio end) || '%' as '2022_RATIO'
    , sum(case when year=2017 then rank end) as '2017_RANK'
    , sum(case when year=2017 then ratio end) || '%' as '2017_RATIO'
    , sum(case when year=2012 then rank end) as '2012_RANK'
    , sum(case when year=2012 then ratio end) || '%' as '2012_RATIO'
from (
    select
        h.AREA_CODE as CODE
        , AREA_NAME as NAME
        , SURVEY_YEAR as year
        , round(100.0 * FOOD_EXP / CONSUMPTION_EXP, 1) as ratio
        , dense_rank() over(partition by SURVEY_YEAR order by round((100.0 * FOOD_EXP / CONSUMPTION_EXP), 1)) as rank
    from 
        HOUSEHOLD_SURVEY h
        left outer join
            AREA a
            on h.AREA_CODE = a.AREA_CODE
    group by
        h.AREA_CODE
        , AREA_NAME
        , SURVEY_YEAR
) t    
group by 
    CODE
    , NAME
order by
    sum(case when year=2022 then rank end)
    , CODE desc
;
提出情報
提出日時2024/02/11 22:47:38
コンテスト第10回 SQLコンテスト
問題食料費の割合
受験者ryatora
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量85 MB
メッセージ
テストケース(通過数/総数)
3/3
状態
メモリ使用量
データパターン1
AC
85 MB
データパターン2
AC
85 MB
データパターン3
AC
85 MB