ソースコード
WITH RATIO_17 AS (
    SELECT
        AREA_CODE
        ,DENSE_RANK() OVER (ORDER BY ROUND((CAST(FOOD_EXP AS REAL) / CAST(CONSUMPTION_EXP AS REAL)) * 100, 1)) AS RANK_2017
        ,ROUND((CAST(FOOD_EXP AS REAL) / CAST(CONSUMPTION_EXP AS REAL)) * 100, 1) || '%' AS RATIO_2017
    FROM
        HOUSEHOLD_SURVEY
    WHERE
        SURVEY_YEAR = 2017
        )
    ,RATIO_12 AS (
        SELECT
        AREA_CODE
        ,DENSE_RANK() OVER (ORDER BY ROUND((CAST(FOOD_EXP AS REAL) / CAST(CONSUMPTION_EXP AS REAL)) * 100, 1)) AS RANK_2012
        ,ROUND((CAST(FOOD_EXP AS REAL) / CAST(CONSUMPTION_EXP AS REAL)) * 100, 1) || '%' AS RATIO_2012
    FROM
        HOUSEHOLD_SURVEY
    WHERE
        SURVEY_YEAR = 2012
        )
SELECT
    HS.AREA_CODE AS CODE
    ,A.AREA_NAME AS NAME
    ,DENSE_RANK() OVER (ORDER BY ROUND((CAST(HS.FOOD_EXP AS REAL) / CAST(HS.CONSUMPTION_EXP AS REAL)) * 100, 1)) AS [2022_RANK]
    ,ROUND((CAST(HS.FOOD_EXP AS REAL) / CAST(HS.CONSUMPTION_EXP AS REAL)) * 100, 1) || '%' AS [2022_RATIO]
    ,RATIO_17.RANK_2017 AS [2017_RANK]
    ,RATIO_17.RATIO_2017 AS [2017_RATIO]
    ,RATIO_12.RANK_2012 AS [2012_RANK]
    ,RATIO_12.RATIO_2012 AS [2012_RATIO]
FROM
    HOUSEHOLD_SURVEY AS HS
LEFT OUTER JOIN
    AREA AS A
  ON
    HS.AREA_CODE = A.AREA_CODE
INNER JOIN
    RATIO_17
  ON
    HS.AREA_CODE = RATIO_17.AREA_CODE
INNER JOIN
    RATIO_12
  ON
    HS.AREA_CODE = RATIO_12.AREA_CODE
WHERE
    SURVEY_YEAR = 2022
ORDER BY
    [2022_RANK] ASC
    ,CODE DESC;
提出情報
提出日時2025/01/14 13:11:09
コンテスト第10回 SQLコンテスト
問題食料費の割合
受験者fffhiro
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量85 MB
メッセージ
テストケース(通過数/総数)
3/3
状態
メモリ使用量
データパターン1
AC
85 MB
データパターン2
AC
85 MB
データパターン3
AC
85 MB