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