ソースコード
with _2022 as 
(
    select
      a.AREA_CODE,
      a.AREA_NAME,
      DENSE_RANK() over (order by round(100.0*hs.FOOD_EXP/hs.CONSUMPTION_EXP,1)) `rank`,
      round(100.0*hs.FOOD_EXP/hs.CONSUMPTION_EXP,1) || "%" `ratio`
    from HOUSEHOLD_SURVEY hs
    left join AREA a using(AREA_CODE)
    where hs.SURVEY_YEAR = 2022
),
_2017 as 
(
    select
      a.AREA_CODE,
      DENSE_RANK() over (order by round(100.0*hs.FOOD_EXP/hs.CONSUMPTION_EXP,1)) `rank`,
      round(100.0*hs.FOOD_EXP/hs.CONSUMPTION_EXP,1) || "%" `ratio`
    from HOUSEHOLD_SURVEY hs
    left join AREA a using(AREA_CODE)
    where hs.SURVEY_YEAR = 2017
),
_2012 as 
(
    select
      a.AREA_CODE,
      DENSE_RANK() over (order by round(100.0*hs.FOOD_EXP/hs.CONSUMPTION_EXP,1)) `rank`,
      round(100.0*hs.FOOD_EXP/hs.CONSUMPTION_EXP,1) || "%" `ratio`
    from HOUSEHOLD_SURVEY hs
    left join AREA a using(AREA_CODE)
    where hs.SURVEY_YEAR = 2012
)
select
  y22.AREA_CODE CODE,
  y22.AREA_NAME NAME,  
  y22.rank `2022_RANK`,
  y22.ratio `2022_RATIO`,
  y17.rank `2017_RANK`,
  y17.ratio `2017_RATIO`,
  y12.rank `2012_RANK`,
  y12.ratio `2012_RATIO`
from _2022 y22
left join _2017 y17 using (AREA_CODE)
left join _2012 y12 using (AREA_CODE)
order by y22.rank, y22.AREA_CODE desc
提出情報
提出日時2024/02/08 23:18:52
コンテスト第10回 SQLコンテスト
問題食料費の割合
受験者tac0x2a
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量85 MB
メッセージ
テストケース(通過数/総数)
3/3
状態
メモリ使用量
データパターン1
AC
84 MB
データパターン2
AC
84 MB
データパターン3
AC
85 MB