ソースコード
with 
tbl1 as(
select
SURVEY_YEAR
,PF_CODE
,sum(ELEMENTARY) as EL
,sum(MIDDLE) as MI
,sum(HIGH) as HI
,sum(JUNIOR_CLG) as JU
,sum(COLLEGE) as CO
,sum(GRADUATE) as GR
from ENROLLMENT_STATUS
where SURVEY_YEAR=2020
group by PF_CODE
order by PF_CODE asc
)
,tbl2 as(
select SURVEY_YEAR as SV_YEAR,PF_CODE,1 as NUM,EL as AMT from tbl1
union all
select SURVEY_YEAR,PF_CODE,2,MI from tbl1
union all
select SURVEY_YEAR,PF_CODE,3,HI from tbl1
union all
select SURVEY_YEAR,PF_CODE,4,JU from tbl1
union all
select SURVEY_YEAR,PF_CODE,5,CO from tbl1
union all
select SURVEY_YEAR,PF_CODE,6,GR from tbl1
)
select
SV_YEAR
,PF_NAME as PREFECTURE
,case NUM when 1 then '小学校' 
        when 2 then '中学校' 
        when 3 then '高校' 
        when 4 then '短大' 
        when 5 then '大学' 
        when 6 then '大学院' end as KIND
,AMT
from tbl2
    inner join PREFECTURE PR on tbl2.PF_CODE =PR.PF_CODE
where AMT is not NULL
order by tbl2.PF_CODE asc,NUM asc
提出情報
提出日時2023/10/04 14:20:59
コンテスト第2回 SQLコンテスト
問題就学状況の表示変換
受験者abcdefghijklmnopqrstuvwxy
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量79 MB
メッセージ
テストケース(通過数/総数)
2/2
状態
メモリ使用量
データパターン1
AC
79 MB
データパターン2
AC
75 MB