ソースコード
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
    ,DENSE_RANK() OVER (ORDER BY R22) AS '2022_RANK'
    ,R22 AS '2022_RATIO'
    ,DENSE_RANK() OVER (ORDER BY R17) AS '2017_RANK'
    ,R22 AS '2017_RATIO'
    ,DENSE_RANK() OVER (ORDER BY R12) AS '2012_RANK'
    ,R22 AS '2012_RATIO'
FROM
    TEMP
ORDER BY 
    3 ASC
    ,1 DESC
提出情報
提出日時2023/12/17 17:28:09
コンテスト第10回 SQLコンテスト
問題食料費の割合
受験者naka-fumi
状態 (詳細)WA
(Wrong Answer: 誤答)
メモリ使用量88 MB
メッセージ
テストケース(通過数/総数)
0/3
状態
メモリ使用量
データパターン1
WA
85 MB
データパターン2
WA
88 MB
データパターン3
WA
86 MB