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