ソースコード
WITH y22 AS (
    SELECT
        AREA_CODE AS ac,
        ROUND(CAST(FOOD_EXP AS REAL)/CAST(CONSUMPTION_EXP AS REAL)*100 , 1) || '%' AS RATIO,
        DENSE_RANK() OVER (ORDER BY ROUND(CAST(FOOD_EXP AS REAL)/CAST(CONSUMPTION_EXP AS REAL)*100 , 1) ASC) AS RNK
    FROM
        HOUSEHOLD_SURVEY 
    WHERE
        SURVEY_YEAR = '2022'
    GROUP BY
        ac
),
y17 AS (
    SELECT
        AREA_CODE AS ac,
        ROUND(CAST(FOOD_EXP AS REAL)/CAST(CONSUMPTION_EXP AS REAL)*100 , 1) || '%' AS RATIO,
        DENSE_RANK() OVER (ORDER BY ROUND(CAST(FOOD_EXP AS REAL)/CAST(CONSUMPTION_EXP AS REAL)*100 , 1) ASC) AS RNK
    FROM
        HOUSEHOLD_SURVEY 
    WHERE
        SURVEY_YEAR = '2017'
    GROUP BY
        ac
),
y12 AS (
    SELECT
        AREA_CODE AS ac,
        ROUND(CAST(FOOD_EXP AS REAL)/CAST(CONSUMPTION_EXP AS REAL)*100 , 1) || '%' AS RATIO,
        DENSE_RANK() OVER (ORDER BY ROUND(CAST(FOOD_EXP AS REAL)/CAST(CONSUMPTION_EXP AS REAL)*100 , 1) ASC) AS RNK
    FROM
        HOUSEHOLD_SURVEY 
    WHERE
        SURVEY_YEAR = '2012'
    GROUP BY
        ac
)

SELECT
    h.AREA_CODE AS CODE,
    a.AREA_NAME AS NAME,
    y22.RNK AS '2022_RANK',
    y22.RATIO AS '2022_RATIO',
    y17.RNK AS '2017_RANK',
    y17.RATIO AS '2017_RATIO',
    y12.RNK AS '2012_RANK',
    y12.RATIO AS '2012_RATIO'
FROM
    HOUSEHOLD_SURVEY AS h
    LEFT OUTER JOIN 
        AREA AS a ON h.AREA_CODE = a.AREA_CODE
    LEFT OUTER JOIN 
       y22 ON h.AREA_CODE = y22.ac
    LEFT OUTER JOIN 
       y17 ON h.AREA_CODE = y17.ac
    LEFT OUTER JOIN 
       y12 ON h.AREA_CODE = y12.ac
GROUP BY
    CODE,
    NAME
ORDER BY
    y22.RNK,
    CODE DESC
提出情報
提出日時2023/12/16 20:51:27
コンテスト第10回 SQLコンテスト
問題食料費の割合
受験者be-yan
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量86 MB
メッセージ
テストケース(通過数/総数)
3/3
状態
メモリ使用量
データパターン1
AC
85 MB
データパターン2
AC
84 MB
データパターン3
AC
86 MB