ソースコード
select 2020 as SV_YEAR, PREFECTURE, KIND, AMT from (
select '小学校' as KIND, 0 as KIND_NUM, sum(ELEMENTARY) as AMT, PF_CODE as CODE, (select p.PF_NAME from PREFECTURE as p where p.PF_CODE = a.PF_CODE) as PREFECTURE from ENROLLMENT_STATUS as a where SURVEY_YEAR = 2020 group by PF_CODE 
union
select '中学校' as KIND, 1 as KIND_NUM, sum(MIDDLE) as AMT, PF_CODE as CODE, (select p.PF_NAME from PREFECTURE as p where p.PF_CODE = b.PF_CODE) as PREFECTURE from ENROLLMENT_STATUS as b where SURVEY_YEAR = 2020 group by PF_CODE
union
select '高校' as KIND, 2 as KIND_NUM, sum(HIGH) as AMT, PF_CODE as CODE, (select p.PF_NAME from PREFECTURE as p where p.PF_CODE = c.PF_CODE) as PREFECTURE from ENROLLMENT_STATUS as c where SURVEY_YEAR = 2020 group by PF_CODE
union
select '短大' as KIND, 3 as KIND_NUM, sum(JUNIOR_CLG) as AMT, PF_CODE as CODE, (select p.PF_NAME from PREFECTURE as p where p.PF_CODE = d.PF_CODE) as PREFECTURE from ENROLLMENT_STATUS as d where SURVEY_YEAR = 2020 group by PF_CODE
union
select '大学' as KIND, 4 as KIND_NUM, sum(COLLEGE) as AMT, PF_CODE as CODE, (select p.PF_NAME from PREFECTURE as p where p.PF_CODE = e.PF_CODE) as PREFECTURE from ENROLLMENT_STATUS as e where SURVEY_YEAR = 2020 group by PF_CODE
union
select '大学院' as KIND, 5 as KIND_NUM, sum(GRADUATE) as AMT, PF_CODE as CODE, (select p.PF_NAME from PREFECTURE as p where p.PF_CODE = f.PF_CODE) as PREFECTURE from ENROLLMENT_STATUS as f where SURVEY_YEAR = 2020 group by PF_CODE
) where AMT is not null order by CODE asc, KIND_NUM asc;
提出情報
提出日時2022/09/21 20:17:24
コンテスト第2回 SQLコンテスト
問題就学状況の表示変換
受験者kazukunn514
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量95 MB
メッセージ
テストケース(通過数/総数)
2/2
状態
メモリ使用量
データパターン1
AC
91 MB
データパターン2
AC
95 MB