ソースコード
WITH t AS (
    SELECT
        PF_CODE
        , SUM(ELEMENTARY) AS SUM_ELEMENTARY
        , SUM(MIDDLE) AS SUM_MIDDLE
        , SUM(HIGH) AS SUM_HIGH
        , SUM(JUNIOR_CLG) AS SUM_JUNIOR_CLG
        , SUM(COLLEGE) AS SUM_COLLEGE
        , SUM(GRADUATE) AS SUM_GRADUATE
    FROM
        ENROLLMENT_STATUS
    WHERE
        SURVEY_YEAR = 2020
    GROUP BY
        PF_CODE
)

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