ソースコード
SELECT 
	 A.Survey_Year AS SV_YEAR
	,P.PF_NAME AS PREFECTURE
	,A.KIND AS KIND
	,A.AMT AS AMT
FROM 
	Prefecture P
INNER JOIN
(
	SELECT 
		Survey_Year 
		,PF_CODE 
		,'小学校' AS KIND
		,SUM(Elementary) AS AMT
	FROM 
		Enrollment_Status
	WHERE
		Survey_Year = 2020
	GROUP BY PF_CODE
	UNION ALL
	SELECT 
		Survey_Year 
		,PF_CODE 
		,'中学校' AS KIND
		,SUM(Middle) AS AMT
	FROM 
		Enrollment_Status
	WHERE
		Survey_Year = 2020
	GROUP BY PF_CODE
	UNION ALL
	SELECT 
		Survey_Year 
		,PF_CODE 
		,'高校' AS KIND
		,SUM(High) AS AMT
	FROM 
		Enrollment_Status
	WHERE
		Survey_Year = 2020
	GROUP BY PF_CODE
	UNION ALL
	SELECT 
		Survey_Year 
		,PF_CODE 
		,'短大' AS KIND
		,SUM(Junior_Clg) AS AMT
	FROM 
		Enrollment_Status
	WHERE
		Survey_Year = 2020
	GROUP BY PF_CODE
	UNION ALL
	SELECT 
		Survey_Year 
		,PF_CODE 
		,'大学' AS KIND
		,SUM(College) AS AMT
	FROM 
		Enrollment_Status
	WHERE
		Survey_Year = 2020
	GROUP BY PF_CODE
	UNION ALL
	SELECT 
		Survey_Year 
		,PF_CODE 
		,'大学院' AS KIND
		,SUM(Graduate) AS AMT
	FROM 
		Enrollment_Status
	WHERE
		Survey_Year = 2020
	GROUP BY PF_CODE
) A
ON 	
	P.PF_CODE = A.PF_CODE
WHERE
	A.AMT IS NOT NULL
ORDER BY
	P.PF_CODE ASC
	,CASE KIND
		WHEN '小学校' THEN 1
		WHEN '中学校' THEN 2
		WHEN '高校' THEN 3
		WHEN '短大' THEN 4
		WHEN '大学' THEN 5
		WHEN '大学院' THEN 6
	 END
;
提出情報
提出日時2022/09/22 09:10:30
コンテスト第2回 SQLコンテスト
問題就学状況の表示変換
受験者Kojiron
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量88 MB
メッセージ
テストケース(通過数/総数)
2/2
状態
メモリ使用量
データパターン1
AC
88 MB
データパターン2
AC
85 MB