ソースコード
SELECT
    HS22.AREA_CODE AS CODE,
    AREA.AREA_NAME AS NAME,
    DENSE_RANK() OVER(
            ORDER BY ROUND(CAST(FOOD_EXP AS REAL)/CAST(CONSUMPTION_EXP AS REAL)*100,1) ASC
        ) AS '2022_RANK',
    ROUND(
        CAST(FOOD_EXP AS REAL)/CAST(CONSUMPTION_EXP AS REAL)*100,1
        ) || '%' AS '2022_RATIO',
    HS17.'2017_RANK',
    HS17.'2017_RATIO',
    HS12.'2012_RANK',
    HS12.'2012_RATIO'
FROM
    HOUSEHOLD_SURVEY AS HS22
    INNER JOIN AREA 
        ON HS22.AREA_CODE=AREA.AREA_CODE
    INNER JOIN (
        SELECT
            AREA_CODE,
            ROUND(
                CAST(FOOD_EXP AS REAL)/CAST(CONSUMPTION_EXP AS REAL)*100,1
                ) || '%' AS '2017_RATIO',
            DENSE_RANK() OVER(
                ORDER BY ROUND(CAST(FOOD_EXP AS REAL)/CAST(CONSUMPTION_EXP AS REAL)*100,1) ASC
            ) AS '2017_RANK'
        FROM
            HOUSEHOLD_SURVEY
        WHERE
            SURVEY_YEAR=2017
        ) AS HS17
        ON HS22.AREA_CODE=HS17.AREA_CODE
    INNER JOIN (
        SELECT
            AREA_CODE,
            ROUND(
                CAST(FOOD_EXP AS REAL)/CAST(CONSUMPTION_EXP AS REAL)*100,1
                ) || '%' AS '2012_RATIO',
            DENSE_RANK() OVER(
                ORDER BY ROUND(CAST(FOOD_EXP AS REAL)/CAST(CONSUMPTION_EXP AS REAL)*100,1) ASC
            ) AS '2012_RANK'
        FROM
            HOUSEHOLD_SURVEY
        WHERE
            SURVEY_YEAR=2012
        ) AS HS12
        ON HS22.AREA_CODE=HS12.AREA_CODE
WHERE
    SURVEY_YEAR=2022
ORDER BY
    DENSE_RANK() OVER(
            ORDER BY ROUND(CAST(FOOD_EXP AS REAL)/CAST(CONSUMPTION_EXP AS REAL)*100,1) ASC
        ) ASC,
    CODE DESC
    ;
提出情報
提出日時2024/04/19 10:52:47
コンテスト第10回 SQLコンテスト
問題食料費の割合
受験者honyara
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量85 MB
メッセージ
テストケース(通過数/総数)
3/3
状態
メモリ使用量
データパターン1
AC
82 MB
データパターン2
AC
84 MB
データパターン3
AC
85 MB