ソースコード
SELECT
 TM.YEAR as SV_YEAR,PR.PF_NAME as PREFECTURE,TM.KIND,TM.AMT
FROM
    (
        SELECT PF_CODE,'小学校' as KIND,SUM(ELEMENTARY) as AMT,SURVEY_YEAR YEAR
        FROM ENROLLMENT_STATUS
        WHERE SURVEY_YEAR = '2020' AND ELEMENTARY IS NOT NULL
        GROUP BY PF_CODE
        UNION
        SELECT PF_CODE,'中学校' as KIND, SUM(MIDDLE) as AMT, SURVEY_YEAR YEAR
        FROM ENROLLMENT_STATUS
        WHERE SURVEY_YEAR = '2020' AND MIDDLE IS NOT NULL
        GROUP BY PF_CODE
        UNION
        SELECT PF_CODE,'高校' as KIND,SUM(HIGH) as AMT,SURVEY_YEAR YEAR
        FROM ENROLLMENT_STATUS
        WHERE SURVEY_YEAR = '2020' AND HIGH IS NOT NULL
        GROUP BY PF_CODE
        UNION
        SELECT PF_CODE,'短大' as KIND,SUM(JUNIOR_CLG) as AMT,SURVEY_YEAR YEAR
        FROM ENROLLMENT_STATUS
        WHERE SURVEY_YEAR = '2020' AND JUNIOR_CLG IS NOT NULL
        GROUP BY PF_CODE
        UNION
        SELECT PF_CODE,'大学' as KIND,SUM(COLLEGE) as AMT,SURVEY_YEAR YEAR
        FROM ENROLLMENT_STATUS
        WHERE SURVEY_YEAR = '2020' AND COLLEGE IS NOT NULL
        GROUP BY PF_CODE
        UNION
        SELECT PF_CODE,'大学院' as KIND,SUM(GRADUATE) as AMT,SURVEY_YEAR as YEAR
        FROM ENROLLMENT_STATUS
        WHERE SURVEY_YEAR = '2020' AND GRADUATE IS NOT NULL
        GROUP BY PF_CODE
    ) TM,
    PREFECTURE PR
WHERE TM.PF_CODE = PR.PF_CODE
ORDER BY TM.PF_CODE ASC,TM.KIND = '小学校' DESC,TM.KIND = '中学校' DESC,TM.KIND = '高校' DESC,TM.KIND = '短大' DESC,TM.KIND = '大学' DESC,TM.KIND = '大学院' DESC
提出情報
提出日時2022/09/22 23:45:46
コンテスト第2回 SQLコンテスト
問題就学状況の表示変換
受験者YusukeYonetani
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量79 MB
メッセージ
テストケース(通過数/総数)
2/2
状態
メモリ使用量
データパターン1
AC
79 MB
データパターン2
AC
79 MB