ソースコード
SELECT 
  SURVEY_YEAR AS SV_YEAR,
  PREFECTURE.PF_NAME AS PREFECTURE,
  (
    CASE WHEN kind_cd = 0 THEN "小学校"
         WHEN kind_cd = 1 THEN "中学校"
         WHEN kind_cd = 2 THEN "高校"
         WHEN kind_cd = 3 THEN "短大"
         WHEN kind_cd = 4 THEN "大学"
         WHEN kind_cd = 5 THEN "大学院"
    END
  ) AS KIND,
  SUM(AMT) AS AMT
FROM (
SELECT
  PF_CODE,
  AGE,
  SURVEY_YEAR,
  ELEMENTARY AS AMT,
  0 AS kind_cd
FROM 
  ENROLLMENT_STATUS
UNION ALL
SELECT
  PF_CODE,
  AGE,
  SURVEY_YEAR,
  MIDDLE AS AMT,
  1 AS kind_cd
FROM 
  ENROLLMENT_STATUS
UNION ALL
SELECT
  PF_CODE,
  AGE,
  SURVEY_YEAR,
  HIGH AS AMT,
  2 AS kind_cd
FROM 
  ENROLLMENT_STATUS
UNION ALL
SELECT
  PF_CODE,
  AGE,
  SURVEY_YEAR,
  JUNIOR_CLG AS AMT,
  3 AS kind_cd
FROM 
  ENROLLMENT_STATUS
UNION ALL
SELECT
  PF_CODE,
  AGE,
  SURVEY_YEAR,
  COLLEGE AS AMT,
  4 AS kind_cd
FROM 
  ENROLLMENT_STATUS
UNION ALL
SELECT
  PF_CODE,
  AGE,
  SURVEY_YEAR,
  GRADUATE AS AMT,
  5 AS kind_cd
FROM 
  ENROLLMENT_STATUS
) AS ENROLLMENT_STATUS
INNER JOIN PREFECTURE ON PREFECTURE.PF_CODE = ENROLLMENT_STATUS.PF_CODE
WHERE AMT IS NOT NULL AND SURVEY_YEAR = 2020
GROUP BY SV_YEAR, PREFECTURE.PF_CODE, kind_cd 
ORDER BY PREFECTURE.PF_CODE ASC, kind_cd ASC
提出情報
提出日時2022/09/22 11:30:11
コンテスト第2回 SQLコンテスト
問題就学状況の表示変換
受験者rerost
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量107 MB
メッセージ
テストケース(通過数/総数)
2/2
状態
メモリ使用量
データパターン1
AC
94 MB
データパターン2
AC
107 MB