ソースコード
with temp as(
    select SURVEY_YEAR, PF_CODE, 1 as kind_code,  '小学校' as KIND, sum(ELEMENTARY) as amt from ENROLLMENT_STATUS where SURVEY_YEAR = 2020 group by PF_CODE
    union all 
    select SURVEY_YEAR, PF_CODE, 2 as kind_code, '中学校' as KIND, sum(MIDDLE) as amt from ENROLLMENT_STATUS where SURVEY_YEAR = 2020 group by PF_CODE
    union all 
    select SURVEY_YEAR, PF_CODE, 3 as kind_code, '高校' as KIND, sum(HIGH) as amt from ENROLLMENT_STATUS where SURVEY_YEAR = 2020 group by PF_CODE
    union all 
    select SURVEY_YEAR, PF_CODE, 4 as kind_code, '短大' as KIND, sum(JUNIOR_CLG) as amt from ENROLLMENT_STATUS where SURVEY_YEAR = 2020 group by PF_CODE
    union all 
    select SURVEY_YEAR, PF_CODE, 5 as kind_code, '大学' as KIND, sum(COLLEGE) as amt from ENROLLMENT_STATUS where SURVEY_YEAR = 2020 group by PF_CODE
    union all 
    select SURVEY_YEAR, PF_CODE, 6 as kind_code, '大学院' as KIND, sum(GRADUATE) as amt from ENROLLMENT_STATUS where SURVEY_YEAR = 2020 group by PF_CODE
)
select 
    SURVEY_YEAR as SV_YEAR, 
    p.PF_NAME as PREFECTURE, 
    KIND, 
    amt as AMT
from temp as t
    inner join PREFECTURE as p on t.PF_CODE = p.PF_CODE
where amt is not null
order by p.PF_CODE asc, kind_code asc
;
提出情報
提出日時2023/10/31 14:34:33
コンテスト第2回 SQLコンテスト
問題就学状況の表示変換
受験者fgdthfjgh
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量77 MB
メッセージ
テストケース(通過数/総数)
2/2
状態
メモリ使用量
データパターン1
AC
77 MB
データパターン2
AC
76 MB