ソースコード


SELECT
    SV_YEAR,
    PREFECTURE,
    KIND,
    AMT
FROM
(
SELECT
PF_CODE,
SURVEY_YEAR SV_YEAR,
PF_NAME PREFECTURE,
"小学校" KIND,
SUM(ELEMENTARY) AMT
FROM ENROLLMENT_STATUS
JOIN PREFECTURE
USING (PF_CODE)
WHERE SV_YEAR = 2020
GROUP BY PF_CODE, SV_YEAR, PREFECTURE

UNION ALL

SELECT
PF_CODE,
SURVEY_YEAR SV_YEAR,
PF_NAME PREFECTURE,
"中学校" KIND,
SUM(MIDDLE) AMT
FROM ENROLLMENT_STATUS
JOIN PREFECTURE
USING (PF_CODE)
WHERE SV_YEAR = 2020
GROUP BY PF_CODE, SV_YEAR, PREFECTURE

UNION ALL

SELECT
PF_CODE,
SURVEY_YEAR SV_YEAR,
PF_NAME PREFECTURE,
"高校" KIND,
SUM(HIGH) AMT
FROM ENROLLMENT_STATUS
JOIN PREFECTURE
USING (PF_CODE)
WHERE SV_YEAR = 2020
GROUP BY PF_CODE, SV_YEAR, PREFECTURE

UNION ALL

SELECT
PF_CODE,
SURVEY_YEAR SV_YEAR,
PF_NAME PREFECTURE,
"短大" KIND,
SUM(JUNIOR_CLG) AMT
FROM ENROLLMENT_STATUS
JOIN PREFECTURE
USING (PF_CODE)
WHERE SV_YEAR = 2020
GROUP BY PF_CODE, SV_YEAR, PREFECTURE

UNION ALL

SELECT
PF_CODE,
SURVEY_YEAR SV_YEAR,
PF_NAME PREFECTURE,
"大学" KIND,
SUM(COLLEGE) AMT
FROM ENROLLMENT_STATUS
JOIN PREFECTURE
USING (PF_CODE)
WHERE SV_YEAR = 2020
GROUP BY PF_CODE, SV_YEAR, PREFECTURE

UNION ALL

SELECT
PF_CODE,
SURVEY_YEAR SV_YEAR,
PF_NAME PREFECTURE,
"大学院" KIND,
SUM(GRADUATE) AMT
FROM ENROLLMENT_STATUS
JOIN PREFECTURE
USING (PF_CODE)
WHERE SV_YEAR = 2020
GROUP BY PF_CODE, SV_YEAR, PREFECTURE

)
WHERE AMT IS NOT NULL
ORDER BY PF_CODE, CASE 
WHEN KIND = "小学校" THEN 1
WHEN KIND = "中学校" THEN 2
WHEN KIND = "高校" THEN 3
WHEN KIND = "短大" THEN 4
WHEN KIND = "大学" THEN 5
WHEN KIND = "大学院" THEN 6
END

提出情報
提出日時2022/09/22 01:12:04
コンテスト第2回 SQLコンテスト
問題就学状況の表示変換
受験者mugenen
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量102 MB
メッセージ
テストケース(通過数/総数)
2/2
状態
メモリ使用量
データパターン1
AC
91 MB
データパターン2
AC
102 MB