ソースコード
WITH RatioData AS (
    SELECT 
        HS.AREA_CODE,
        HS.SURVEY_YEAR,
        ROUND((CAST(HS.FOOD_EXP AS REAL) / HS.CONSUMPTION_EXP) * 100, 1) AS RATIO
    FROM 
        HOUSEHOLD_SURVEY HS
    WHERE 
        HS.SURVEY_YEAR IN (2022, 2017, 2012)
), RankedData AS (
    SELECT 
        RD.AREA_CODE,
        RD.SURVEY_YEAR,
        RD.RATIO,
        DENSE_RANK() OVER (PARTITION BY RD.SURVEY_YEAR ORDER BY RD.RATIO ASC, RD.AREA_CODE DESC) AS RANK
    FROM 
        RatioData RD
)
SELECT 
    A.AREA_CODE AS CODE,
    A.AREA_NAME AS NAME,
    R2022.RANK AS "2022_RANK",
    R2022.RATIO || '%' AS "2022_RATIO",
    R2017.RANK AS "2017_RANK",
    R2017.RATIO || '%' AS "2017_RATIO",
    R2012.RANK AS "2012_RANK",
    R2012.RATIO || '%' AS "2012_RATIO"
FROM 
    AREA A
LEFT JOIN 
    RankedData R2022 ON A.AREA_CODE = R2022.AREA_CODE AND R2022.SURVEY_YEAR = 2022
LEFT JOIN 
    RankedData R2017 ON A.AREA_CODE = R2017.AREA_CODE AND R2017.SURVEY_YEAR = 2017
LEFT JOIN 
    RankedData R2012 ON A.AREA_CODE = R2012.AREA_CODE AND R2012.SURVEY_YEAR = 2012
ORDER BY 
    "2022_RANK" ASC, A.AREA_CODE DESC
;
提出情報
提出日時2023/12/18 11:53:54
コンテスト第10回 SQLコンテスト
問題食料費の割合
受験者kmd2525
状態 (詳細)WA
(Wrong Answer: 誤答)
メモリ使用量102 MB
メッセージ
テストケース(通過数/総数)
0/3
状態
メモリ使用量
データパターン1
WA
98 MB
データパターン2
WA
86 MB
データパターン3
WA
102 MB