ソースコード
WITH TEMP AS(
SELECT
    H.AREA_CODE AS CODE
    ,AREA_NAME AS NAME
    ,ROUND(CAST(SUM(CASE WHEN SURVEY_YEAR = 2022 THEN FOOD_EXP ELSE 0 END) AS FLOAT)
    /SUM(CASE WHEN SURVEY_YEAR = 2022 THEN CONSUMPTION_EXP ELSE 0 END) 
    * 100,1) AS 'R22'
    ,ROUND(CAST(SUM(CASE WHEN SURVEY_YEAR = 2017 THEN FOOD_EXP ELSE 0 END) AS FLOAT)
    /SUM(CASE WHEN SURVEY_YEAR = 2017 THEN CONSUMPTION_EXP ELSE 0 END) 
    * 100,1) AS 'R17'    
    ,ROUND(CAST(SUM(CASE WHEN SURVEY_YEAR = 2012 THEN FOOD_EXP ELSE 0 END) AS FLOAT)
    /SUM(CASE WHEN SURVEY_YEAR = 2012 THEN CONSUMPTION_EXP ELSE 0 END) 
    * 100,1) AS 'R12'    
FROM
    HOUSEHOLD_SURVEY H
    LEFT JOIN AREA A
    ON H.AREA_CODE = A.AREA_CODE
GROUP BY
    H.AREA_CODE
)
SELECT
    CODE
    ,NAME
    ,RANK() OVER (ORDER BY R22) AS '2022_RANK'
    ,(cast(R22 as varchar) || '%') AS '2022_RATIO'
    ,RANK() OVER (ORDER BY R17) AS '2017_RANK'
    ,(cast(R17 as varchar) || '%') AS '2017_RATIO'
    ,RANK() OVER (ORDER BY R12) AS '2012_RANK'
    ,(cast(R12 as varchar) || '%') AS '2012_RATIO'
FROM
    TEMP
ORDER BY 
    3 ASC
    ,1 DESC
提出情報
提出日時2023/12/19 09:57:47
コンテスト第10回 SQLコンテスト
問題食料費の割合
受験者naka-fumi
状態 (詳細)WA
(Wrong Answer: 誤答)
メモリ使用量85 MB
メッセージ
テストケース(通過数/総数)
0/3
状態
メモリ使用量
データパターン1
WA
84 MB
データパターン2
WA
84 MB
データパターン3
WA
85 MB