ソースコード
with ratio2022 as (
select 
h.AREA_CODE as CODE,
a.AREA_NAME as NAME,
round(cast(sum(FOOD_EXP) as real) / sum(CONSUMPTION_EXP) * 100, 1)  as RATIO
from   HOUSEHOLD_SURVEY h
join   AREA a on h.AREA_CODE = a.AREA_CODE
where  h.SURVEY_YEAR = 2022
group by h.AREA_CODE,a.AREA_NAME
), ratio2017 as (
select 
h.AREA_CODE as CODE,
a.AREA_NAME as NAME,
round(cast(sum(FOOD_EXP) as real) / sum(CONSUMPTION_EXP) * 100, 1)  as RATIO
from   HOUSEHOLD_SURVEY h
join   AREA a on h.AREA_CODE = a.AREA_CODE
where  h.SURVEY_YEAR = 2017
group by h.AREA_CODE,a.AREA_NAME
), ratio2012 as (
select 
h.AREA_CODE as CODE,
a.AREA_NAME as NAME,
cast(round(cast(sum(FOOD_EXP) as real) / sum(CONSUMPTION_EXP) * 100, 1) as real) as RATIO
from   HOUSEHOLD_SURVEY h
join   AREA a on h.AREA_CODE = a.AREA_CODE
where  h.SURVEY_YEAR = 2012
group by h.AREA_CODE,a.AREA_NAME
)
select ratio2022.CODE, ratio2022.NAME,
DENSE_RANK()over(ORDER BY ratio2022.RATIO) as "2022_RANK",
ratio2022.RATIO || '%' as "2022_RATIO",
DENSE_RANK()over(ORDER BY ratio2017.RATIO) as "2017_RANK",
ratio2017.RATIO || '%' as "2017_RATIO",
DENSE_RANK()over(ORDER BY ratio2012.RATIO) as "2012_RANK",
ratio2012.RATIO || '%' as "2012_RATIO"
from   ratio2022
left join ratio2017
on  ratio2022.CODE = ratio2017.CODE
left join ratio2012
on  ratio2022.CODE = ratio2012.CODE
order by 3, 1 desc
提出情報
提出日時2024/04/28 18:32:05
コンテスト第10回 SQLコンテスト
問題食料費の割合
受験者yunyun8686
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量86 MB
メッセージ
テストケース(通過数/総数)
3/3
状態
メモリ使用量
データパターン1
AC
85 MB
データパターン2
AC
86 MB
データパターン3
AC
85 MB