ソースコード
with table_2012 AS(
    select a.area_code
        , round(cast(s.FOOD_EXP AS double) / cast(s.CONSUMPTION_EXP AS double) * 100, 1)
            || '%' AS '2012_RATIO'
        , RANK() OVER(order by cast(s.FOOD_EXP AS double) / cast(s.CONSUMPTION_EXP AS double) desc)
            AS '2012_RANK'
    from AREA a
    inner join HOUSEHOLD_SURVEY s
        on a.area_code = s.area_code
    where s.survey_year = 2012
    group by a.area_code
)

, table_2017 AS(
    select a.area_code
        , round(cast(s.FOOD_EXP AS double) / cast(s.CONSUMPTION_EXP AS double) * 100, 1)
            || '%' AS '2017_RATIO'
        , RANK() OVER(order by cast(s.FOOD_EXP AS double) / cast(s.CONSUMPTION_EXP AS double) desc)
            AS '2017_RANK'
    from AREA a
    inner join HOUSEHOLD_SURVEY s
        on a.area_code = s.area_code
    where s.survey_year = 2017
    group by a.area_code
)

, table_2022 AS(
    select a.area_code
        , round(cast(s.FOOD_EXP AS double) / cast(s.CONSUMPTION_EXP AS double) * 100, 1)
            || '%' AS '2022_RATIO'
        , RANK() OVER(order by cast(s.FOOD_EXP AS double) / cast(s.CONSUMPTION_EXP AS double) desc)
            AS '2022_RANK'
    from AREA a
    inner join HOUSEHOLD_SURVEY s
        on a.area_code = s.area_code
    where s.survey_year = 2022
    group by a.area_code
)
select
    a.area_code AS CODE
    , a.area_name AS NAME
    , t2022.'2022_RANK'
    , t2022.'2022_RATIO'
    , t2017.'2017_RANK'
    , t2017.'2017_RATIO'
    , t2012.'2012_RANK'
    , t2012.'2012_RATIO'
from area a
inner join table_2012 t2012
    on a.area_code = t2012.area_code
inner join table_2017 t2017
    on a.area_code = t2017.area_code
inner join table_2022 t2022
    on a.area_code = t2022.area_code
order by t2022.'2022_RANK', a.area_code desc;
提出情報
提出日時2023/12/17 22:58:42
コンテスト第10回 SQLコンテスト
問題食料費の割合
受験者sql_yowayowa
状態 (詳細)WA
(Wrong Answer: 誤答)
メモリ使用量86 MB
メッセージ
テストケース(通過数/総数)
0/3
状態
メモリ使用量
データパターン1
WA
85 MB
データパターン2
WA
84 MB
データパターン3
WA
86 MB