ソースコード
WITH TBL_12 AS(
    SELECT
        AREA_CODE
        ,ROUND(100.0 * FOOD_EXP / CONSUMPTION_EXP, 1) AS RATIO
    FROM
        HOUSEHOLD_SURVEY
    WHERE
        SURVEY_YEAR = 2012
), TBL_17 AS(
    SELECT
        AREA_CODE
        ,ROUND(100.0 * FOOD_EXP / CONSUMPTION_EXP, 1) AS RATIO
    FROM
        HOUSEHOLD_SURVEY
    WHERE
        SURVEY_YEAR = 2017
), TBL_22 AS(
    SELECT
        AREA_CODE
        ,ROUND(100.0 * FOOD_EXP / CONSUMPTION_EXP, 1) AS RATIO
    FROM
        HOUSEHOLD_SURVEY
    WHERE
        SURVEY_YEAR = 2022
)
SELECT
    TBL_12.AREA_CODE AS CODE
    ,AREA.AREA_NAME AS NAME
    ,DENSE_RANK() OVER(ORDER BY TBL_22.RATIO) AS '2022_RANK'
    ,TBL_22.RATIO|| "%" AS '2022_RATIO'
    ,DENSE_RANK() OVER(ORDER BY TBL_17.RATIO) AS '2017_RANK'
    ,TBL_17.RATIO || "%" AS '2017_RATIO'
    ,DENSE_RANK() OVER(ORDER BY TBL_12.RATIO) AS '2012_RANK'
    ,TBL_12.RATIO || "%" AS '2012_RATIO'
FROM
    TBL_12
        INNER JOIN TBL_17
            ON TBL_12.AREA_CODE = TBL_17.AREA_CODE
        INNER JOIN TBL_22
            ON TBL_12.AREA_CODE = TBL_22.AREA_CODE
        INNER JOIN AREA
            ON TBL_12.AREA_CODE = AREA.AREA_CODE
ORDER BY
    "2022_RANK" ASC
    , CODE DESC
提出情報
提出日時2024/03/11 15:06:53
コンテスト第10回 SQLコンテスト
問題食料費の割合
受験者citrus_sudachi
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量84 MB
メッセージ
テストケース(通過数/総数)
3/3
状態
メモリ使用量
データパターン1
AC
82 MB
データパターン2
AC
83 MB
データパターン3
AC
84 MB