ソースコード
WITH T AS(
    SELECT
        HOUSEHOLD_SURVEY.AREA_CODE AS CODE,
        AREA.AREA_NAME AS NAME,
        ROUND(100.0 * SUM(
            CASE SURVEY_YEAR
                WHEN 2022 THEN FOOD_EXP
                ELSE 0
            END
        ) / SUM(
            CASE SURVEY_YEAR
                WHEN 2022 THEN CONSUMPTION_EXP
                ELSE 0
            END
        ), 1) AS "2022_RATIO",
        ROUND(100.0 * SUM(
            CASE SURVEY_YEAR
                WHEN 2017 THEN FOOD_EXP
                ELSE 0
            END
        ) / SUM(
            CASE SURVEY_YEAR
                WHEN 2017 THEN CONSUMPTION_EXP
                ELSE 0
            END
        ), 1) AS "2017_RATIO",
        ROUND(100.0 * SUM(
            CASE SURVEY_YEAR
                WHEN 2012 THEN FOOD_EXP
                ELSE 0
            END
        ) / SUM(
            CASE SURVEY_YEAR
                WHEN 2012 THEN CONSUMPTION_EXP
                ELSE 0
            END
        ), 1) AS "2012_RATIO"
    FROM
        HOUSEHOLD_SURVEY
        INNER JOIN
            AREA ON HOUSEHOLD_SURVEY.AREA_CODE = AREA.AREA_CODE
    GROUP BY
        HOUSEHOLD_SURVEY.AREA_CODE
)
SELECT
    CODE,
    NAME,
    RANK() OVER(ORDER BY "2022_RATIO" ASC) AS "2022_RANK",
    "2022_RATIO" || '%' AS "2022_RATIO",
    RANK() OVER(ORDER BY "2017_RATIO" ASC) AS "2017_RANK",
    "2017_RATIO" || '%' AS "2017_RATIO",
    RANK() OVER(ORDER BY "2012_RATIO" ASC) AS "2012_RANK",
    "2012_RATIO" || '%' AS "2012_RATIO"
FROM
    T
ORDER BY
    "2022_RANK" ASC,
    CODE DESC
    
提出情報
提出日時2023/12/16 13:19:34
コンテスト第10回 SQLコンテスト
問題食料費の割合
受験者tokusakurai
状態 (詳細)WA
(Wrong Answer: 誤答)
メモリ使用量86 MB
メッセージ
テストケース(通過数/総数)
0/3
状態
メモリ使用量
データパターン1
WA
86 MB
データパターン2
WA
86 MB
データパターン3
WA
86 MB