ソースコード
WITH temp AS (
    SELECT
        es.SURVEY_YEAR AS SV_YEAR
        , es.PF_CODE
        , pf.PF_NAME AS PREFECTURE
        , SUM(es.ELEMENTARY) AS SUM_ELEMENTARY
        , SUM(es.MIDDLE) AS SUM_MIDDLE
        , SUM(es.HIGH) AS SUM_HIGH
        , SUM(es.JUNIOR_CLG) AS SUM_JUNIOR_CLG
        , SUM(es.COLLEGE) AS SUM_COLLEGE
        , SUM(es.GRADUATE) AS SUM_GRADUATE
    FROM
        ENROLLMENT_STATUS AS es
    INNER JOIN
        PREFECTURE AS pf
    ON
        es.PF_CODE = pf.PF_CODE
    WHERE
        SURVEY_YEAR = 2020
    GROUP BY
        es.PF_CODE, es.SURVEY_YEAR
)

SELECT
    SV_YEAR
    , PREFECTURE
    , KIND
    , AMT
FROM
    (
    SELECT SV_YEAR, PF_CODE, PREFECTURE, 1 AS KIND_CODE, '小学校' AS KIND, SUM_ELEMENTARY AS AMT FROM temp
    UNION
    SELECT SV_YEAR, PF_CODE, PREFECTURE, 2 AS KIND_CODE, '中学校' AS KIND, SUM_MIDDLE AS AMT FROM temp
    UNION
    SELECT SV_YEAR, PF_CODE, PREFECTURE, 3 AS KIND_CODE, '高校' AS KIND, SUM_HIGH AS AMT FROM temp
    UNION
    SELECT SV_YEAR, PF_CODE, PREFECTURE, 4 AS KIND_CODE, '短大' AS KIND, SUM_JUNIOR_CLG AS AMT FROM temp
    UNION
    SELECT SV_YEAR, PF_CODE, PREFECTURE, 5 AS KIND_CODE, '大学' AS KIND, SUM_COLLEGE AS AMT FROM temp
    UNION
    SELECT SV_YEAR, PF_CODE, PREFECTURE, 6 AS KIND_CODE, '大学院' AS KIND, SUM_GRADUATE AS AMT FROM temp
    )
WHERE
    AMT IS NOT NULL
ORDER BY
    PF_CODE ASC, KIND_CODE ASC
;
提出情報
提出日時2023/10/11 03:06:00
コンテスト第2回 SQLコンテスト
問題就学状況の表示変換
受験者wasese
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量78 MB
メッセージ
テストケース(通過数/総数)
2/2
状態
メモリ使用量
データパターン1
AC
78 MB
データパターン2
AC
76 MB