ソースコード
select TOTAL_TBL.SURVEY_YEAR as SV_YEAR, PRE.PF_NAME as PREFECTURE, TOTAL_TBL.KIND, TOTAL_TBL.AMT 
from (select SURVEY_YEAR, PF_CODE, '小学校' as KIND, sum(ELEMENTARY) as AMT, 0 as KINDCODE from ENROLLMENT_STATUS where SURVEY_YEAR='2020' and ELEMENTARY is not null
group by PF_CODE, KIND
union 
select SURVEY_YEAR, PF_CODE, '中学校' as KIND, sum(MIDDLE) as AMT, 1 as KINDCODE from ENROLLMENT_STATUS where SURVEY_YEAR='2020' and MIDDLE is not null
group by PF_CODE, KIND
union 
select SURVEY_YEAR, PF_CODE, '高校' as KIND, sum(HIGH) as AMT, 2 as KINDCODE from ENROLLMENT_STATUS where SURVEY_YEAR='2020' and HIGH is not null
group by PF_CODE, KIND
union 
select SURVEY_YEAR, PF_CODE, '短大' as KIND, sum(JUNIOR_CLG) as AMT, 3 as KINDCODE from ENROLLMENT_STATUS where SURVEY_YEAR='2020' and JUNIOR_CLG is not null
group by PF_CODE, KIND
union 
select SURVEY_YEAR, PF_CODE, '大学' as KIND, sum(COLLEGE) as AMT, 4 as KINDCODE from ENROLLMENT_STATUS where SURVEY_YEAR='2020' and COLLEGE is not null
group by PF_CODE, KIND
union 
select SURVEY_YEAR, PF_CODE, '大学院' as KIND, sum(GRADUATE) as AMT, 5 as KINDCODE from ENROLLMENT_STATUS where SURVEY_YEAR='2020' and GRADUATE is not null
group by PF_CODE, KIND
) TOTAL_TBL,
PREFECTURE PRE
WHERE TOTAL_TBL.PF_CODE=PRE.PF_CODE
order by TOTAL_TBL.PF_CODE asc, 
TOTAL_TBL.KINDCODE asc
提出情報
提出日時2023/06/26 16:44:37
コンテスト第2回 SQLコンテスト
問題就学状況の表示変換
受験者yamada_hi_roky
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量79 MB
メッセージ
テストケース(通過数/総数)
2/2
状態
メモリ使用量
データパターン1
AC
79 MB
データパターン2
AC
77 MB