ソースコード
WITH t AS (SELECT
 ENROLLMENT_STATUS.SURVEY_YEAR as SV_YEAR,
 PREFECTURE.PF_NAME as PREFECTURE,
 PREFECTURE.PF_CODE as PF_CODE,
 sum(ENROLLMENT_STATUS.ELEMENTARY) as 小学校,
 sum(ENROLLMENT_STATUS.MIDDLE) as 中学校,
 sum(ENROLLMENT_STATUS.HIGH) as 高校,
 sum(ENROLLMENT_STATUS.JUNIOR_CLG) as 短大,
 sum(ENROLLMENT_STATUS.COLLEGE) as 大学,
 sum(ENROLLMENT_STATUS.GRADUATE) as 大学院
FROM
 ENROLLMENT_STATUS
JOIN
 PREFECTURE
 on ENROLLMENT_STATUS.PF_CODE = PREFECTURE.PF_CODE
WHERE
 ENROLLMENT_STATUS.SURVEY_YEAR = 2020
GROUP BY
 ENROLLMENT_STATUS.SURVEY_YEAR, PREFECTURE.PF_NAME 
)

SELECT
 SV_YEAR, PREFECTURE, 区分 as KIND, AMT
FROM 
 (
    SELECT
     SV_YEAR, PREFECTURE, '小学校' as 区分, 小学校 as AMT, 1 as No, PF_CODE
    FROM 
     t
    UNION ALL
    SELECT
     SV_YEAR, PREFECTURE, '中学校' as 区分, 中学校 as AMT, 2 as No, PF_CODE
    FROM 
     t
    UNION ALL
    SELECT
     SV_YEAR, PREFECTURE, '高校' as 区分, 高校 as AMT, 3 as No, PF_CODE
    FROM 
     t
    UNION ALL
    SELECT
     SV_YEAR, PREFECTURE, '短大' as 区分, 短大 as AMT, 4 as No, PF_CODE
    FROM 
     t
    UNION ALL
    SELECT
     SV_YEAR, PREFECTURE, '大学' as 区分, 大学 as AMT, 5 as No, PF_CODE
    FROM 
     t
    UNION ALL
    SELECT
     SV_YEAR, PREFECTURE, '大学院' as 区分, 大学院 as AMT, 6 as No, PF_CODE
    FROM 
     t
) as w
WHERE 
 AMT IS NOT NULL
ORDER BY
 PF_CODE asc, No asc
 
提出情報
提出日時2022/09/22 03:28:57
コンテスト第2回 SQLコンテスト
問題就学状況の表示変換
受験者omg_granddd
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量78 MB
メッセージ
テストケース(通過数/総数)
2/2
状態
メモリ使用量
データパターン1
AC
78 MB
データパターン2
AC
76 MB