ソースコード
WITH T1 AS(
    SELECT
        HOUSEHOLD_SURVEY.AREA_CODE AS CODE,
        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
), T2 AS(
    SELECT
        CODE,
        NAME,
        DENSE_RANK() OVER(ORDER BY "2022_RATIO" ASC) AS "2022_RANK",
        "2022_RATIO" || "%" AS "2022_RATIO",
        DENSE_RANK() OVER(ORDER BY "2017_RATIO" ASC) AS "2017_RANK",
        "2017_RATIO" || "%" AS "2017_RATIO",
        DENSE_RANK() OVER(ORDER BY "2012_RATIO" ASC) AS "2012_RANK",
        "2012_RATIO" || "%" AS "2012_RATIO"
    FROM
        T1
    ORDER BY
        "2022_RANK" ASC,
        CODE DESC
)
SELECT
    *
    FROM T2
提出情報
提出日時2024/02/18 20:39:38
コンテスト第10回 SQLコンテスト
問題食料費の割合
受験者tokusakurai
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量86 MB
メッセージ
テストケース(通過数/総数)
3/3
状態
メモリ使用量
データパターン1
AC
86 MB
データパターン2
AC
85 MB
データパターン3
AC
85 MB