ソースコード
SELECT
    SV_YEAR
    ,PREFECTURE
    ,KIND
    ,AMT
FROM (
    SELECT
         ENR.SURVEY_YEAR AS SV_YEAR
        ,ENR.PF_CODE AS CODE
        ,PRE.PF_NAME AS PREFECTURE
        ,1      KINDNO
        ,'小学校'KIND
        ,SUM(ELEMENTARY)AMT
    FROM  ENROLLMENT_STATUS ENR
    LEFT JOIN PREFECTURE PRE
    ON ENR.PF_CODE = PRE.PF_CODE
    WHERE  ENR.SURVEY_YEAR  = 2020
    AND ENR.ELEMENTARY IS NOT  NULL
    GROUP BY ENR.SURVEY_YEAR
            ,PRE.PF_NAME 
    
    UNION 
    SELECT
         ENR.SURVEY_YEAR AS SV_YEAR
        ,ENR.PF_CODE AS CODE
        ,PRE.PF_NAME AS PREFECTURE
        ,2      KINDNO
        ,'中学校'KIND
        ,SUM(MIDDLE)AMT
    FROM  ENROLLMENT_STATUS ENR
    LEFT JOIN PREFECTURE PRE
    ON ENR.PF_CODE = PRE.PF_CODE
    WHERE  ENR.SURVEY_YEAR  = 2020
    AND ENR.MIDDLE IS NOT  NULL
    GROUP BY ENR.SURVEY_YEAR
            ,PRE.PF_NAME 
    UNION 
    SELECT
         ENR.SURVEY_YEAR AS SV_YEAR
        ,ENR.PF_CODE AS CODE
        ,PRE.PF_NAME AS PREFECTURE
        ,3      KINDNO
        ,'高校'KIND
        ,SUM(HIGH)AMT
    FROM  ENROLLMENT_STATUS ENR
    LEFT JOIN PREFECTURE PRE
    ON ENR.PF_CODE = PRE.PF_CODE
    WHERE  ENR.SURVEY_YEAR  = 2020
    AND ENR.HIGH IS NOT  NULL
    GROUP BY ENR.SURVEY_YEAR
            ,PRE.PF_NAME 
    UNION 
    SELECT
         ENR.SURVEY_YEAR AS SV_YEAR
        ,ENR.PF_CODE AS CODE
        ,PRE.PF_NAME AS PREFECTURE
        ,4      KINDNO
        ,'短大'KIND
        ,SUM(JUNIOR_CLG)AMT
    FROM  ENROLLMENT_STATUS ENR
    LEFT JOIN PREFECTURE PRE
    ON ENR.PF_CODE = PRE.PF_CODE
    WHERE  ENR.SURVEY_YEAR  = 2020
    AND ENR.JUNIOR_CLG IS NOT  NULL
    GROUP BY ENR.SURVEY_YEAR
            ,PRE.PF_NAME 
    UNION 
    SELECT
         ENR.SURVEY_YEAR AS SV_YEAR
        ,ENR.PF_CODE AS CODE
        ,PRE.PF_NAME AS PREFECTURE
        ,5      KINDNO
        ,'大学'KIND
        ,SUM(COLLEGE)AMT
    FROM  ENROLLMENT_STATUS ENR
    LEFT JOIN PREFECTURE PRE
    ON ENR.PF_CODE = PRE.PF_CODE
    WHERE  ENR.SURVEY_YEAR  = 2020
    AND ENR.COLLEGE IS NOT  NULL
    GROUP BY ENR.SURVEY_YEAR
            ,PRE.PF_NAME 
    UNION 
    SELECT
         ENR.SURVEY_YEAR AS SV_YEAR
        ,ENR.PF_CODE AS CODE
        ,PRE.PF_NAME AS PREFECTURE
        ,6      KINDNO
        ,'大学院'KIND
        ,SUM(GRADUATE)AMT
    FROM  ENROLLMENT_STATUS ENR
    LEFT JOIN PREFECTURE PRE
    ON ENR.PF_CODE = PRE.PF_CODE
    WHERE  ENR.SURVEY_YEAR  = 2020
    AND ENR.GRADUATE IS NOT  NULL
    GROUP BY ENR.SURVEY_YEAR
            ,PRE.PF_NAME 
    )
ORDER BY  CODE ASC
          ,KINDNO ASC
        
提出情報
提出日時2022/09/21 17:01:55
コンテスト第2回 SQLコンテスト
問題就学状況の表示変換
受験者jojojojoo
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量86 MB
メッセージ
テストケース(通過数/総数)
2/2
状態
メモリ使用量
データパターン1
AC
86 MB
データパターン2
AC
79 MB