ソースコード
SELECT
    t1.SURVEY_YEAR AS SV_YEAR
   ,t3.PF_NAME AS PREFECTURE
   ,t2.KIND_NAME AS KIND
   ,t1.SUM_COUNT AS AMT
FROM
   (
      SELECT
          SURVEY_YEAR
         ,PF_CODE
         ,'ELEMENTARY' AS KIND_ID
         ,SUM(ELEMENTARY) AS SUM_COUNT
      FROM
         ENROLLMENT_STATUS
      WHERE
         SURVEY_YEAR = 2020
      GROUP BY
         PF_CODE
      UNION
      SELECT
          SURVEY_YEAR
         ,PF_CODE
         ,'MIDDLE' AS KIND_ID
         ,SUM(MIDDLE)     SUM_COUNT
      FROM
         ENROLLMENT_STATUS
      WHERE
         SURVEY_YEAR = 2020
      GROUP BY
         PF_CODE
      UNION
      SELECT
          SURVEY_YEAR
         ,PF_CODE
         ,'HIGH' AS KIND_ID
         ,SUM(HIGH)       SUM_COUNT
      FROM
         ENROLLMENT_STATUS
      WHERE
         SURVEY_YEAR = 2020
      GROUP BY
         PF_CODE
      UNION
      SELECT
          SURVEY_YEAR
         ,PF_CODE
         ,'JUNIOR_CLG' AS KIND_ID
         ,SUM(JUNIOR_CLG) SUM_COUNT
      FROM
         ENROLLMENT_STATUS
      WHERE
         SURVEY_YEAR = 2020
      GROUP BY
         PF_CODE
      UNION
      SELECT
          SURVEY_YEAR
         ,PF_CODE
         ,'COLLEGE' AS KIND_ID
         ,SUM(COLLEGE)    SUM_COUNT
      FROM
         ENROLLMENT_STATUS
      WHERE
         SURVEY_YEAR = 2020
      GROUP BY
         PF_CODE
      UNION
      SELECT
          SURVEY_YEAR
         ,PF_CODE
         ,'GRADUATE' AS KIND_ID
         ,SUM(GRADUATE)   SUM_COUNT
      FROM
         ENROLLMENT_STATUS
      WHERE
         SURVEY_YEAR = 2020
      GROUP BY
         PF_CODE
   ) AS t1
   ,(
                SELECT 'ELEMENTARY' AS KIND_ID, '小学校' AS KIND_NAME, 1 AS SHOW_SEQ
      UNION ALL SELECT 'MIDDLE'     AS KIND_ID, '中学校' AS KIND_NAME, 2 AS SHOW_SEQ
      UNION ALL SELECT 'HIGH'       AS KIND_ID, '高校'   AS KIND_NAME, 3 AS SHOW_SEQ
      UNION ALL SELECT 'JUNIOR_CLG' AS KIND_ID, '短大'   AS KIND_NAME, 4 AS SHOW_SEQ
      UNION ALL SELECT 'COLLEGE'    AS KIND_ID, '大学'   AS KIND_NAME, 5 AS SHOW_SEQ
      UNION ALL SELECT 'GRADUATE'   AS KIND_ID, '大学院' AS KIND_NAME, 6 AS SHOW_SEQ
   ) AS t2
   ,PREFECTURE AS t3
WHERE
       t1.KIND_ID = t2.KIND_ID
   AND t1.SUM_COUNT IS NOT NULL
   AND t1.PF_CODE = t3.PF_CODE
ORDER BY
    t1.PF_CODE ASC
   ,t2.SHOW_SEQ ASC
提出情報
提出日時2022/09/22 08:36:34
コンテスト第2回 SQLコンテスト
問題就学状況の表示変換
受験者nezumi
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量95 MB
メッセージ
テストケース(通過数/総数)
2/2
状態
メモリ使用量
データパターン1
AC
95 MB
データパターン2
AC
92 MB