ソースコード
select 
    2020 SV_YEAR, 
    (select PF_NAME FROM Prefecture p where p.PF_CODE=u.PF_CODE) PREFECTURE,
    KIND,
    sum(AMOUT) AMT
from (
    select SURVEY_YEAR, PF_CODE, '小学校' KIND, 1 KIND_NUM, ELEMENTARY AMOUT from ENROLLMENT_STATUS where SURVEY_YEAR = 2020 and ELEMENTARY IS NOT NULL
    union all
    select SURVEY_YEAR, PF_CODE, '中学校' KIND, 2 KIND_NUM, MIDDLE AMOUT from ENROLLMENT_STATUS where SURVEY_YEAR = 2020 and MIDDLE IS NOT NULL
    union all
    select SURVEY_YEAR, PF_CODE, '高校' KIND, 3 KIND_NUM, HIGH AMOUT from ENROLLMENT_STATUS where SURVEY_YEAR = 2020 and HIGH IS NOT NULL
    union all
    select SURVEY_YEAR, PF_CODE, '短大' KIND, 4 KIND_NUM, JUNIOR_CLG AMOUT from ENROLLMENT_STATUS where SURVEY_YEAR = 2020 and JUNIOR_CLG IS NOT NULL
    union all
    select SURVEY_YEAR, PF_CODE, '大学' KIND, 5 KIND_NUM, COLLEGE AMOUT from ENROLLMENT_STATUS where SURVEY_YEAR = 2020 and COLLEGE IS NOT NULL
    union all
    select SURVEY_YEAR, PF_CODE, '大学院' KIND, 6 KIND_NUM, GRADUATE AMOUT from ENROLLMENT_STATUS where SURVEY_YEAR = 2020 and GRADUATE IS NOT NULL
) u
group by SURVEY_YEAR, PF_CODE, KIND, KIND_NUM
having AMT IS NOT NULL
order by PF_CODE, KIND_NUM 
提出情報
提出日時2022/09/21 21:35:45
コンテスト第2回 SQLコンテスト
問題就学状況の表示変換
受験者jau5
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量100 MB
メッセージ
テストケース(通過数/総数)
2/2
状態
メモリ使用量
データパターン1
AC
100 MB
データパターン2
AC
100 MB