ソースコード
SELECT
     MAIN.SURVEY_YEAR AS SV_YEAR
    ,P.PF_NAME AS PREFECTURE
    ,MAIN.KIND
    ,MAIN.AMT
FROM
(
    SELECT
         ES.SURVEY_YEAR
        ,ES.PF_CODE
        ,'小学校' AS KIND
        ,1 AS NUM
        ,SUM(ES.ELEMENTARY) AS AMT
    FROM
        ENROLLMENT_STATUS AS ES
    WHERE
        ES.SURVEY_YEAR = 2020
    GROUP BY
         ES.SURVEY_YEAR
        ,ES.PF_CODE
    
    UNION ALL
    
    SELECT
         ES.SURVEY_YEAR
        ,ES.PF_CODE
        ,'中学校' AS KIND
        ,2 AS NUM
        ,SUM(ES.MIDDLE) AS AMT
    FROM
        ENROLLMENT_STATUS AS ES
    WHERE
        ES.SURVEY_YEAR = 2020
    GROUP BY
         ES.SURVEY_YEAR
        ,ES.PF_CODE
    
    UNION ALL
    
    SELECT
         ES.SURVEY_YEAR
        ,ES.PF_CODE
        ,'高校' AS KIND
        ,3 AS NUM
        ,SUM(ES.HIGH) AS AMT
    FROM
        ENROLLMENT_STATUS AS ES
    WHERE
        ES.SURVEY_YEAR = 2020
    GROUP BY
         ES.SURVEY_YEAR
        ,ES.PF_CODE
    
    UNION ALL
    
    SELECT
         ES.SURVEY_YEAR
        ,ES.PF_CODE
        ,'短大' AS KIND
        ,4 AS NUM
        ,SUM(ES.JUNIOR_CLG) AS AMT
    FROM
        ENROLLMENT_STATUS AS ES
    WHERE
        ES.SURVEY_YEAR = 2020
    GROUP BY
         ES.SURVEY_YEAR
        ,ES.PF_CODE
    
    UNION ALL
    
    SELECT
         ES.SURVEY_YEAR
        ,ES.PF_CODE
        ,'大学' AS KIND
        ,5 AS NUM
        ,SUM(ES.COLLEGE) AS AMT
    FROM
        ENROLLMENT_STATUS AS ES
    WHERE
        ES.SURVEY_YEAR = 2020
    GROUP BY
         ES.SURVEY_YEAR
        ,ES.PF_CODE
    
    UNION ALL
    
    SELECT
         ES.SURVEY_YEAR
        ,ES.PF_CODE
        ,'大学院' AS KIND
        ,6 AS NUM
        ,SUM(ES.GRADUATE) AS AMT
    FROM
        ENROLLMENT_STATUS AS ES
    WHERE
        ES.SURVEY_YEAR = 2020
    GROUP BY
         ES.SURVEY_YEAR
        ,ES.PF_CODE
) AS MAIN

INNER JOIN
    PREFECTURE AS P
ON
    P.PF_CODE = MAIN.PF_CODE

WHERE
    MAIN.AMT IS NOT NULL
    
ORDER BY
     MAIN.PF_CODE ASC
    ,MAIN.NUM ASC
提出情報
提出日時2024/02/15 00:46:34
コンテスト第2回 SQLコンテスト
問題就学状況の表示変換
受験者mo
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量86 MB
メッセージ
テストケース(通過数/総数)
2/2
状態
メモリ使用量
データパターン1
AC
86 MB
データパターン2
AC
84 MB