ソースコード
SELECT SV_YEAR, PREFECTURE, KIND, AMT FROM (
SELECT pf_code, 1 AS sort, survey_year AS SV_YEAR, pf_name AS PREFECTURE, '小学校' AS KIND, SUM(elementary) AS AMT FROM enrollment_status JOIN prefecture USING (pf_code) WHERE survey_year = 2020 AND elementary IS NOT NULL GROUP BY pf_code, KIND
UNION
SELECT pf_code, 2 AS sort, survey_year AS SV_YEAR, pf_name AS PREFECTURE, '中学校' AS KIND, SUM(middle) AS AMT FROM enrollment_status JOIN prefecture USING (pf_code) WHERE survey_year = 2020 AND middle IS NOT NULL GROUP BY pf_code, KIND
UNION
SELECT pf_code, 3 AS sort, survey_year AS SV_YEAR, pf_name AS PREFECTURE, '高校' AS KIND, SUM(high) AS AMT FROM enrollment_status JOIN prefecture USING (pf_code) WHERE survey_year = 2020 AND high IS NOT NULL GROUP BY pf_code, KIND
UNION
SELECT pf_code, 4 AS sort, survey_year AS SV_YEAR, pf_name AS PREFECTURE, '短大' AS KIND, SUM(junior_clg) AS AMT FROM enrollment_status JOIN prefecture USING (pf_code) WHERE survey_year = 2020 AND junior_clg IS NOT NULL GROUP BY pf_code, KIND
UNION
SELECT pf_code, 5 AS sort, survey_year AS SV_YEAR, pf_name AS PREFECTURE, '大学' AS KIND, SUM(college) AS AMT FROM enrollment_status JOIN prefecture USING (pf_code) WHERE survey_year = 2020 AND college IS NOT NULL GROUP BY pf_code, KIND
UNION
SELECT pf_code, 6 AS sort, survey_year AS SV_YEAR, pf_name AS PREFECTURE, '大学院' AS KIND, SUM(graduate) AS AMT FROM enrollment_status JOIN prefecture USING (pf_code) WHERE survey_year = 2020 AND graduate IS NOT NULL GROUP BY pf_code, KIND
) ORDER BY pf_code, sort
提出情報
提出日時2022/09/22 08:51:41
コンテスト第2回 SQLコンテスト
問題就学状況の表示変換
受験者matsuu
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量79 MB
メッセージ
テストケース(通過数/総数)
2/2
状態
メモリ使用量
データパターン1
AC
79 MB
データパターン2
AC
77 MB