ソースコード
with a as (
select
    SURVEY_YEAR ye,
    AREA_CODE ac,
    round(cast(FOOD_EXP as real)*100.0/ cast(CONSUMPTION_EXP as real),1) || '%' ratio
from HOUSEHOLD_SURVEY
group by SURVEY_YEAR,AREA_CODE)

select 
ac as CODE,
area_name as NAME,

max(case when ye=2022 then ratio else null end) as '2022_RATIO' , 
max(case when ye=2022 then rnk else null end) as '2022_RANK', 
max(case when ye=2017 then ratio else null end) as '2017_RATIO' , 
max(case when ye=2017 then rnk else null end) as '2017_RANK', 
max(case when ye=2012 then ratio else null end) as '2012_RATIO'  ,
max(case when ye=2012 then rnk else null end) as '2012_RANK'

 from
(
select 
    ye,
    ac,
    ratio,
    dense_rank() over(
        partition by ye order by ratio
    ) rnk
     from a
     ) a
     join area on area.area_code=a.ac
     group by ac
order by 3,1 desc
提出情報
提出日時2024/04/19 15:50:55
コンテスト第10回 SQLコンテスト
問題食料費の割合
受験者orekwys
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量84 MB
メッセージ
テストケース(通過数/総数)
3/3
状態
メモリ使用量
データパターン1
AC
84 MB
データパターン2
AC
84 MB
データパターン3
AC
84 MB