ソースコード
select 
s.sv_year as SV_YEAR,
p.pf_name  as PREFECTURE,
s.kind as KIND,
s.amt as AMT
from 
(
select 
es.survey_year as SV_YEAR
, es.pf_code as pf_code 
, '小学校' as kind
, sum(es.elementary) as amt
, 1 as ord
from 
enrollment_status es 
where 
es.survey_year = 2020
group by 
es.survey_year 
, es.pf_code 
union all 
select 
es.survey_year as SV_YEAR
, es.pf_code as pf_code 
, '中学校' as kind
, sum(es.MIDDLE) as amt
, 2 as ord
from 
enrollment_status es 
where 
es.survey_year = 2020
group by 
es.survey_year 
, es.pf_code 
union all 
select 
es.survey_year as SV_YEAR
, es.pf_code as pf_code 
, '高校' as kind
, sum(es.high) as amt
, 3 as ord
from 
enrollment_status es 
where 
es.survey_year = 2020
group by 
es.survey_year 
, es.pf_code 
union all 
select 
es.survey_year as SV_YEAR
, es.pf_code as pf_code 
, '短大' as kind
, sum(es.junior_clg) as amt
, 4 as ord
from 
enrollment_status es 
where 
es.survey_year = 2020
group by 
es.survey_year 
, es.pf_code 
union all 
select 
es.survey_year as SV_YEAR
, es.pf_code as pf_code 
, '大学' as kind
, sum(es.college) as amt
, 5 as ord
from 
enrollment_status es 
where 
es.survey_year = 2020
group by 
es.survey_year 
, es.pf_code 
union all 
select 
es.survey_year as SV_YEAR
, es.pf_code as pf_code 
, '大学院' as kind
, sum(es.graduate) as amt
, 6 as ord
from 
enrollment_status es 
where 
es.survey_year = 2020
group by 
es.survey_year 
, es.pf_code 
)as s
inner join 
prefecture p 
on
p.pf_code = s.pf_code
where 
s.amt is not null
order by 
p.pf_code asc 
, s.ord asc
提出情報
提出日時2022/09/22 01:18:39
コンテスト第2回 SQLコンテスト
問題就学状況の表示変換
受験者ccppjsrb
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量83 MB
メッセージ
テストケース(通過数/総数)
2/2
状態
メモリ使用量
データパターン1
AC
81 MB
データパターン2
AC
83 MB