ソースコード
with BASE as(
select
	A.SURVEY_YEAR as SV_YEAR
,	A.PF_CODE
,	B.PF_NAME as PREFECTURE
,	A.ELEMENTARY
,	A.MIDDLE
,	A.HIGH
,	A.JUNIOR_CLG
,	A.COLLEGE
,	A.GRADUATE
from
	ENROLLMENT_STATUS A
,	PREFECTURE B
where
	A.PF_CODE = B.PF_CODE
and	A.SURVEY_YEAR = '2020'
),
BASE2 as(
select
	SV_YEAR
,	PF_CODE
,	PREFECTURE
,	'小学校' AS KIND
,	'1' as NUM
,	ELEMENTARY as AMT
from
	BASE
where
	ELEMENTARY IS NOT NULL
union
select
	SV_YEAR
,	PF_CODE
,	PREFECTURE
,	'中学校' AS KIND
,	'2' as NUM
,	MIDDLE as AMT
from
	BASE
where
	MIDDLE IS NOT NULL
union
select
	SV_YEAR
,	PF_CODE
,	PREFECTURE
,	'高校' AS KIND
,	'3' as NUM
,	HIGH as AMT
from
	BASE
where
	HIGH IS NOT NULL
union
select
	SV_YEAR
,	PF_CODE
,	PREFECTURE
,	'短大' AS KIND
,	'4' as NUM
,	JUNIOR_CLG as AMT
from
	BASE
where
	JUNIOR_CLG IS NOT NULL
union
select
	SV_YEAR
,	PF_CODE
,	PREFECTURE
,	'大学' AS KIND
,	'4' as NUM
,	COLLEGE as AMT
from
	BASE
where
	COLLEGE IS NOT NULL
union
select
	SV_YEAR
,	PF_CODE
,	PREFECTURE
,	'大学院' AS KIND
,	'5' as NUM
,	GRADUATE as AMT
from
	BASE
where
	GRADUATE IS NOT NULL
)
SELECT
	SV_YEAR
,	PREFECTURE
,	KIND
,	AMT
from
	BASE2
order by
	PF_CODE
,	NUM
提出情報
提出日時2022/09/21 21:15:31
コンテスト第2回 SQLコンテスト
問題就学状況の表示変換
受験者r1000000
状態 (詳細)WA
(Wrong Answer: 誤答)
メモリ使用量103 MB
メッセージ
テストケース(通過数/総数)
0/2
状態
メモリ使用量
データパターン1
WA
100 MB
データパターン2
WA
103 MB