ソースコード
with y2022 as(
SELECT
area_code,
round((FOOD_EXP*100.0 / h.CONSUMPTION_EXP),1) a


FROM
HOUSEHOLD_SURVEY h
where survey_year=2022

group by 
Area_code
),
 y2017 as(
SELECT
area_code,
round((FOOD_EXP*100.0 / h.CONSUMPTION_EXP),1) b

FROM
HOUSEHOLD_SURVEY h
where survey_year=2017

group by 
Area_code
),
 y2012 as(
SELECT
area_code,
round((FOOD_EXP*100.0 / h.CONSUMPTION_EXP),1) c

FROM
HOUSEHOLD_SURVEY h
where survey_year=2012

group by 
Area_code
), result as (


select y2022.area_code CODE,

a||'%' '2022_RATIO',
b||'%' '2017_RATIO',
c||'%' '2012_RATIO',
cast(dense_rank() over (order by a) as integer) as  '2022_RANK',
dense_rank() over (order by b) '2017_RANK',

dense_rank() over (order by c) '2012_RANK'


from y2022 inner join y2017 on y2022.area_code=y2017.area_code inner join y2012 on 
y2022.area_code=y2012.area_code

order by '2022_RANK'
)
select result.*,a.area_name NAME from result inner join AREA a
on result.code=a.area_code
order by 2 asc,a.area_code desc

提出情報
提出日時2023/12/17 23:55:27
コンテスト第10回 SQLコンテスト
問題食料費の割合
受験者noneof383
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量85 MB
メッセージ
テストケース(通過数/総数)
3/3
状態
メモリ使用量
データパターン1
AC
84 MB
データパターン2
AC
84 MB
データパターン3
AC
85 MB