ソースコード
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'
    ,(cast(R22 as varchar) || '%') AS '2022_RATIO'
    ,DENSE_RANK() OVER (ORDER BY R17) AS '2017_RANK'
    ,(cast(R17 as varchar) || '%') AS '2017_RATIO'
    ,DENSE_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:59:20
コンテスト第10回 SQLコンテスト
問題食料費の割合
受験者naka-fumi
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量86 MB
メッセージ
テストケース(通過数/総数)
3/3
状態
メモリ使用量
データパターン1
AC
86 MB
データパターン2
AC
85 MB
データパターン3
AC
86 MB