ソースコード

with a as(
select
e.SURVEY_YEAR as SV_YEAR
,e.PF_CODE as code
,p.PF_NAME as PREFECTURE
,sum(e.ELEMENTARY) as '小学校'
,sum(e.MIDDLE) as '中学校'
,sum(e.HIGH) as '高校'
,sum(e.JUNIOR_CLG) as '短大'
,sum(e.COLLEGE)  as '大学'
,sum(e.GRADUATE) as '大学院'
from ENROLLMENT_STATUS as e
inner join PREFECTURE as p
on e.PF_CODE=p.PF_CODE
where SV_YEAR='2020' 
group by code
),
b as
(
select 
code,SV_YEAR,0 as NO,'小学校' as KIND,PREFECTURE,小学校 as AMT from a union all 
select
code,SV_YEAR,1 as NO,'中学校' as KIND,PREFECTURE,中学校 as AMT from a union all 
select
code,SV_YEAR,2 as NO,'高校' as KIND,PREFECTURE,高校 as AMT from a union all 
select
code,SV_YEAR,3 as NO,'短大' as KIND,PREFECTURE,短大 as AMT from a union all 
select
code,SV_YEAR,4 as NO,'大学' as KIND,PREFECTURE,大学 as AMT from a union all 
select
code,SV_YEAR,5 as NO,'大学院' as KIND,PREFECTURE,大学院 as AMT from a
)
select
SV_YEAR,KIND,PREFECTURE,AMT
from b
where AMT is not NULL
order by code,NO

提出情報
提出日時2023/12/11 11:16:33
コンテスト第2回 SQLコンテスト
問題就学状況の表示変換
受験者yoshino
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量84 MB
メッセージ
テストケース(通過数/総数)
2/2
状態
メモリ使用量
データパターン1
AC
84 MB
データパターン2
AC
84 MB