ソースコード
with RATIO as (
select
   SURVEY_YEAR as YEAR
 , AREA_CODE as CODE
 , round(FOOD_EXP * 100.0 / CONSUMPTION_EXP , 1) || "%" as RATIO
from
  HOUSEHOLD_SURVEY
where
 SURVEY_YEAR in (2022, 2017, 2012))

select
   R22.CODE
 , AREA_NAME as NAME
 , dense_rank() over (order by R22.RATIO asc) as "2022_RANK"
 , R22.RATIO as "2022_RATIO"
 , dense_rank() over (order by R17.RATIO asc) as "2017_RANK"
 , R17.RATIO as "2017_RATIO"
 , dense_rank() over (order by R12.RATIO asc) as "2012_RANK"
 , R12.RATIO as "2012_RATIO"
from
   RATIO R22
 join RATIO R17 on R17.YEAR = 2017 and R17.CODE = R22.CODE 
 join RATIO R12 on R12.YEAR = 2012 and R12.CODE = R22.CODE 
 join AREA A on A.AREA_CODE = R22.CODE
where
     R22.YEAR = 2022
order by
   R22.RATIO asc
 , R22.CODE desc;
提出情報
提出日時2023/12/15 23:17:29
コンテスト第10回 SQLコンテスト
問題食料費の割合
受験者udy
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量85 MB
メッセージ
テストケース(通過数/総数)
3/3
状態
メモリ使用量
データパターン1
AC
84 MB
データパターン2
AC
85 MB
データパターン3
AC
85 MB