ソースコード
with ta as (select SURVEY_YEAR, AREA_CODE, round(FOOD_EXP * 100.0 / CONSUMPTION_EXP,1) as RATIO
from HOUSEHOLD_SURVEY)
, tb as (
select *, dense_rank() over(partition by SURVEY_YEAR order by RATIO) as RANK,  case when substr(cast(RATIO as string),-2,1) = "." then cast(RATIO as string) || "%" else cast(RATIO as string) || ".0%" end as RATIO_1
from ta)


select AREA_CODE as CODE, AREA_NAME as NAME, `2022_RANK`,`2022_RATIO`,`2017_RANK`,`2017_RATIO`,`2012_RANK`,`2012_RATIO`
from (select AREA_CODE,RATIO_1 as `2022_RATIO`,RANK as `2022_RANK`  from tb where SURVEY_YEAR = 2022)
left join (select AREA_CODE,RATIO_1 as `2017_RATIO`,RANK as `2017_RANK`  from tb where SURVEY_YEAR = 2017) using (AREA_CODE)
left join (select AREA_CODE,RATIO_1 as `2012_RATIO`,RANK as `2012_RANK`  from tb where SURVEY_YEAR = 2012) using (AREA_CODE)
left join AREA using (AREA_CODE)
order by `2022_RANK` asc, CODE desc
提出情報
提出日時2023/12/18 08:05:51
コンテスト第10回 SQLコンテスト
問題食料費の割合
受験者Tomii9273
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量86 MB
メッセージ
テストケース(通過数/総数)
3/3
状態
メモリ使用量
データパターン1
AC
86 MB
データパターン2
AC
84 MB
データパターン3
AC
86 MB