ソースコード
WITH A AS(    
SELECT
    SURVEY_YEAR
    ,PF_CODE
    ,SUM(ELEMENTARY) AS E
    ,SUM(MIDDLE) AS M
    ,SUM(HIGH) AS H
    ,SUM(JUNIOR_CLG) AS J
    ,SUM(COLLEGE) AS C
    ,SUM(GRADUATE) AS G
FROM
    ENROLLMENT_STATUS
WHERE
    SURVEY_YEAR = '2020'
GROUP BY
    SURVEY_YEAR
    ,PF_CODE
)

SELECT 
    SURVEY_YEAR AS SV_YEAR
    ,PF_NAME AS PREFECTURE
    ,KIND
    ,AMT
FROM
(SELECT
    SURVEY_YEAR
    ,PF_CODE
    ,'小学校' AS KIND
    ,E AS AMT
FROM A
UNION
SELECT
    SURVEY_YEAR
    ,PF_CODE
    ,'中学校' AS KIND
    ,M AS AMT
FROM A
UNION
SELECT
    SURVEY_YEAR
    ,PF_CODE
    ,'高校' AS KIND
    ,H AS AMT
FROM A
UNION
SELECT
    SURVEY_YEAR
    ,PF_CODE
    ,'短大' AS KIND
    ,J AS AMT
FROM A
UNION
SELECT
    SURVEY_YEAR
    ,PF_CODE
    ,'大学' AS KIND
    ,C AS AMT
FROM A
UNION
SELECT
    SURVEY_YEAR
    ,PF_CODE
    ,'大学院' AS KIND
    ,G AS AMT
FROM A) B
INNER JOIN PREFECTURE P ON B.PF_CODE = P.PF_CODE
WHERE AMT IS NOT NULL
ORDER BY
    B.PF_CODE
    ,CASE KIND
    WHEN '小学校' THEN 1
    WHEN '中学校' THEN 2
    WHEN '高校' THEN 3
    WHEN '短大' THEN 4
    WHEN '大学' THEN 5
    WHEN '大学院' THEN 6
    END

提出情報
提出日時2022/09/21 18:43:19
コンテスト第2回 SQLコンテスト
問題就学状況の表示変換
受験者nanana
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量102 MB
メッセージ
テストケース(通過数/総数)
2/2
状態
メモリ使用量
データパターン1
AC
102 MB
データパターン2
AC
99 MB