ソースコード
WITH Y2022 AS (
  SELECT AREA_CODE
        ,ROUND(FOOD_EXP * 1.0 / CONSUMPTION_EXP * 1.0 * 100 , 1) RATIO
        ,DENSE_RANK() OVER (ORDER BY ROUND(FOOD_EXP * 1.0 / CONSUMPTION_EXP * 1.0 * 100 , 1)) RNK
    FROM (SELECT *
            FROM HOUSEHOLD_SURVEY
           WHERE SURVEY_YEAR = 2022)
), Y2017 AS (
  SELECT AREA_CODE
        ,ROUND(FOOD_EXP * 1.0 / CONSUMPTION_EXP * 1.0 * 100 , 1) RATIO
        ,DENSE_RANK() OVER (ORDER BY ROUND(FOOD_EXP * 1.0 / CONSUMPTION_EXP * 1.0 * 100 , 1)) RNK
    FROM (SELECT *
            FROM HOUSEHOLD_SURVEY
           WHERE SURVEY_YEAR = 2017)
), Y2012 AS (
  SELECT AREA_CODE
        ,ROUND(FOOD_EXP * 1.0 / CONSUMPTION_EXP * 1.0 * 100 , 1) RATIO
        ,DENSE_RANK() OVER (ORDER BY ROUND(FOOD_EXP * 1.0 / CONSUMPTION_EXP * 1.0 * 100 , 1)) RNK
    FROM (SELECT *
            FROM HOUSEHOLD_SURVEY
           WHERE SURVEY_YEAR = 2012)
)
SELECT AREA.AREA_CODE CODE
      ,AREA.AREA_NAME NAME
      ,Y22.RNK AS '2022_RANK'
      ,Y22.RATIO || '%' AS '2022_RATIO'
      ,Y17.RNK '2017_RANK'
      ,Y17.RATIO || '%' '2017_RATIO'
      ,Y12.RNK '2012_RANK'
      ,Y12.RATIO || '%' '2012_RATIO'
  FROM AREA
  LEFT OUTER JOIN Y2022 Y22
    ON AREA.AREA_CODE = Y22.AREA_CODE
  LEFT OUTER JOIN Y2017 Y17
    ON AREA.AREA_CODE = Y17.AREA_CODE
  LEFT OUTER JOIN Y2012 Y12
    ON AREA.AREA_CODE = Y12.AREA_CODE
ORDER BY Y22.RNK
        ,AREA.AREA_CODE DESC
提出情報
提出日時2023/12/17 15:31:06
コンテスト第10回 SQLコンテスト
問題食料費の割合
受験者yakiniku_tabetai_pakupaku
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量90 MB
メッセージ
テストケース(通過数/総数)
3/3
状態
メモリ使用量
データパターン1
AC
89 MB
データパターン2
AC
90 MB
データパターン3
AC
85 MB