ソースコード
WITH RANKING2022 AS (
    SELECT
        2022
        , a.AREA_CODE AS CODE
        , AREA_NAME   AS NAME
        , ROUND(CAST(FOOD_EXP AS FLOAT) / CONSUMPTION_EXP * 100, 1) || '%' AS RATIO
        , DENSE_RANK() OVER (ORDER BY CAST(FOOD_EXP AS FLOAT) / CONSUMPTION_EXP * 100 DESC) AS RANK
    FROM
        HOUSEHOLD_SURVEY a
        INNER JOIN AREA b ON
            a.AREA_CODE = b.AREA_CODE
    WHERE
        SURVEY_YEAR = 2022
),
RANKING2017 AS (
    SELECT
        2017
        , a.AREA_CODE AS CODE
        , AREA_NAME   AS NAME
        , ROUND(CAST(FOOD_EXP AS FLOAT) / CONSUMPTION_EXP * 100, 1) || '%' AS RATIO
        , DENSE_RANK() OVER (ORDER BY CAST(FOOD_EXP AS FLOAT) / CONSUMPTION_EXP * 100 DESC) AS RANK
    FROM
        HOUSEHOLD_SURVEY a
        INNER JOIN AREA b ON
            a.AREA_CODE = b.AREA_CODE
    WHERE
        SURVEY_YEAR = 2017
),
RANKING2012 AS (
    SELECT
        2012
        , a.AREA_CODE AS CODE
        , AREA_NAME   AS NAME
        , ROUND(CAST(FOOD_EXP AS FLOAT) / CONSUMPTION_EXP * 100, 1) || '%' AS RATIO
        , DENSE_RANK() OVER (ORDER BY CAST(FOOD_EXP AS FLOAT) / CONSUMPTION_EXP * 100 DESC) AS RANK
    FROM
        HOUSEHOLD_SURVEY a
        INNER JOIN AREA b ON
            a.AREA_CODE = b.AREA_CODE
    WHERE
        SURVEY_YEAR = 2012
)
SELECT
    a.CODE
    , a.NAME
    , a.RANK  AS '2022_RANK'
    , a.RATIO AS '2022_RATIO'
    , b.RANK  AS '2017_RANK'
    , b.RATIO AS '2017_RATIO'
    , c.RANK  AS '2012_RANK'
    , c.RATIO AS '2012_RATIO'
FROM
    RANKING2022 a
    LEFT JOIN RANKING2017 b ON
        a.CODE = b.CODE
    LEFT JOIN RANKING2012 c ON
        a.CODE = c.CODE
ORDER BY
    a.RANK
    , a.CODE DESC
;
提出情報
提出日時2024/02/09 11:49:27
コンテスト第10回 SQLコンテスト
問題食料費の割合
受験者SQL2022
状態 (詳細)WA
(Wrong Answer: 誤答)
メモリ使用量86 MB
メッセージ
テストケース(通過数/総数)
0/3
状態
メモリ使用量
データパターン1
WA
86 MB
データパターン2
WA
84 MB
データパターン3
WA
85 MB