ソースコード
SELECT
    TMP.SV_YEAR,
    PF.PF_NAME as PREFECTURE,
    TMP.KIND,
    TMP.AMT    
FROM (
    SELECT
        SURVEY_YEAR as SV_YEAR,
        PF_CODE,
        '小学校' as KIND,
        SUM(ELEMENTARY) as AMT
    FROM
        ENROLLMENT_STATUS ES
    WHERE 
        SURVEY_YEAR = 2020
    GROUP BY
        PF_CODE
    UNION ALL
    SELECT
        SURVEY_YEAR as SV_YEAR,
        PF_CODE,
        '中学校' as KIND,
        SUM(MIDDLE) as AMT
    FROM
        ENROLLMENT_STATUS ES
    WHERE 
        SURVEY_YEAR = 2020
    GROUP BY
        PF_CODE
    UNION ALL
    SELECT
        SURVEY_YEAR as SV_YEAR,
        PF_CODE,
        '高校' as KIND,
        SUM(HIGH) as AMT
    FROM
        ENROLLMENT_STATUS ES
    WHERE 
        SURVEY_YEAR = 2020
    GROUP BY
        PF_CODE
    UNION ALL
    SELECT
        SURVEY_YEAR as SV_YEAR,
        PF_CODE, 
        '短大' as KIND,
        SUM(JUNIOR_CLG) as AMT
    FROM
        ENROLLMENT_STATUS ES
    WHERE 
        SURVEY_YEAR = 2020
    GROUP BY
        PF_CODE
    UNION ALL
    SELECT
        SURVEY_YEAR as SV_YEAR,
        PF_CODE,
        '大学' as KIND,
        SUM(COLLEGE) as AMT
    FROM
        ENROLLMENT_STATUS ES
    WHERE 
        SURVEY_YEAR = 2020
    GROUP BY
        PF_CODE
    UNION ALL
    SELECT
        SURVEY_YEAR as SV_YEAR,
        PF_CODE,
        '大学院' as KIND,
        SUM(GRADUATE) as AMT
    FROM
        ENROLLMENT_STATUS ES
    WHERE 
        SURVEY_YEAR = 2020
    GROUP BY
        PF_CODE
    ) TMP
INNER JOIN
    PREFECTURE PF
    ON PF.PF_CODE = TMP.PF_CODE
WHERE
    TMP.AMT is not NULL
ORDER BY
    TMP.PF_CODE,
    CASE KIND
      WHEN '小学校' THEN 1
      WHEN '中学校' THEN 2
      WHEN '高校' THEN 3
      WHEN '短大' THEN 4
      WHEN '大学' THEN 5
      WHEN '大学院' THEN 6
    END;
提出情報
提出日時2023/06/30 23:27:29
コンテスト第2回 SQLコンテスト
問題就学状況の表示変換
受験者Amac
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量78 MB
メッセージ
テストケース(通過数/総数)
2/2
状態
メモリ使用量
データパターン1
AC
78 MB
データパターン2
AC
76 MB