ソースコード
SELECT
    E.SURVEY_YEAR AS SV_YEAR,
    PF.PF_NAME AS PREFECTURE,
    KIND,
    SUM(Students) AS AMT
FROM (
    SELECT SURVEY_YEAR, PF_CODE, '小学校' AS KIND, ELEMENTARY AS Students FROM ENROLLMENT_STATUS WHERE SURVEY_YEAR = 2020 AND ELEMENTARY IS NOT NULL
    UNION ALL
    SELECT SURVEY_YEAR, PF_CODE, '中学校' AS KIND, MIDDLE AS Students FROM ENROLLMENT_STATUS WHERE SURVEY_YEAR = 2020 AND MIDDLE IS NOT NULL
    UNION ALL
    SELECT SURVEY_YEAR, PF_CODE, '高校' AS KIND, HIGH AS Students FROM ENROLLMENT_STATUS WHERE SURVEY_YEAR = 2020 AND HIGH IS NOT NULL
    UNION ALL
    SELECT SURVEY_YEAR, PF_CODE, '短大' AS KIND, JUNIOR_CLG AS Students FROM ENROLLMENT_STATUS WHERE SURVEY_YEAR = 2020 AND JUNIOR_CLG IS NOT NULL
    UNION ALL
    SELECT SURVEY_YEAR, PF_CODE, '大学' AS KIND, COLLEGE AS Students FROM ENROLLMENT_STATUS WHERE SURVEY_YEAR = 2020 AND COLLEGE IS NOT NULL
    UNION ALL
    SELECT SURVEY_YEAR, PF_CODE, '大学院' AS KIND, GRADUATE AS Students FROM ENROLLMENT_STATUS WHERE SURVEY_YEAR = 2020 AND GRADUATE IS NOT NULL
) E
LEFT JOIN PREFECTURE PF ON E.PF_CODE = PF.PF_CODE
GROUP BY E.SURVEY_YEAR, PF.PF_NAME, KIND
ORDER BY PF.PF_CODE, 
    CASE KIND
        WHEN '小学校' THEN 1
        WHEN '中学校' THEN 2
        WHEN '高校' THEN 3
        WHEN '短大' THEN 4
        WHEN '大学' THEN 5
        WHEN '大学院' THEN 6
    END;
提出情報
提出日時2024/01/25 08:27:48
コンテスト第2回 SQLコンテスト
問題就学状況の表示変換
受験者doro
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量86 MB
メッセージ
テストケース(通過数/総数)
2/2
状態
メモリ使用量
データパターン1
AC
86 MB
データパターン2
AC
84 MB