ソースコード
SELECT
    TEMP.SV_YEAR,
    PREFECTURE.PF_NAME AS "PREFECTURE",
    TEMP.KIND,
    TEMP.AMT    
FROM (
    SELECT
        SURVEY_YEAR AS SV_YEAR,
        PF_CODE,
        '小学校' AS KIND,
        SUM(ELEMENTARY) AS AMT,
        1 AS ORDER_NUM
    FROM ENROLLMENT_STATUS
    WHERE SURVEY_YEAR = 2020
    GROUP BY PF_CODE
    UNION ALL
    SELECT
        SURVEY_YEAR AS SV_YEAR,
        PF_CODE,
        '中学校' AS KIND,
        SUM(MIDDLE) AS AMT,
        2 AS ORDER_NUM
    FROM ENROLLMENT_STATUS
    WHERE SURVEY_YEAR = 2020
    GROUP BY PF_CODE
    UNION ALL
    SELECT
        SURVEY_YEAR AS SV_YEAR,
        PF_CODE,
        '高校' AS KIND,
        SUM(HIGH) AS AMT,
        3 AS ORDER_NUM
    FROM ENROLLMENT_STATUS
    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,
        4 AS ORDER_NUM
    FROM ENROLLMENT_STATUS
    WHERE SURVEY_YEAR = 2020
    GROUP BY PF_CODE
    UNION ALL
    SELECT
        SURVEY_YEAR AS SV_YEAR,
        PF_CODE,
        '大学' AS KIND,
        SUM(COLLEGE) AS AMT,
        5 AS ORDER_NUM
    FROM ENROLLMENT_STATUS
    WHERE SURVEY_YEAR = 2020
    GROUP BY PF_CODE
    UNION ALL
    SELECT
        SURVEY_YEAR AS SV_YEAR,
        PF_CODE,
        '大学院' AS KIND,
        SUM(GRADUATE) AS AMT,
        6 AS ORDER_NUM
    FROM ENROLLMENT_STATUS
    WHERE SURVEY_YEAR = 2020
    GROUP BY PF_CODE
) AS TEMP
INNER JOIN PREFECTURE ON TEMP.PF_CODE = PREFECTURE.PF_CODE
WHERE TEMP.AMT IS NOT NULL
ORDER BY TEMP.PF_CODE ASC, ORDER_NUM ASC;

提出情報
提出日時2024/06/08 16:47:02
コンテスト第2回 SQLコンテスト
問題就学状況の表示変換
受験者hatarino
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量94 MB
メッセージ
テストケース(通過数/総数)
2/2
状態
メモリ使用量
データパターン1
AC
94 MB
データパターン2
AC
93 MB