ソースコード
SELECT SV_YEAR,PREFECTURE,KIND,AMT FROM(
SELECT
    SURVEY_YEAR AS SV_YEAR,
    PF_NAME AS PREFECTURE,
    "ELEMENTARY" AS KIND,
    SUM(ELEMENTARY) AS AMT, P.PF_CODE
FROM 
PREFECTURE P LEFT JOIN ENROLLMENT_STATUS E ON P.PF_CODE = E.PF_CODE
WHERE E.SURVEY_YEAR = 2020
GROUP BY SURVEY_YEAR, P.PF_CODE
UNION
SELECT
    SURVEY_YEAR AS SV_YEAR,
    PF_NAME AS PREFECTURE,
    "MIDDLE" AS KIND,
    SUM(MIDDLE) AS AMT, P.PF_CODE
FROM 
PREFECTURE P LEFT JOIN ENROLLMENT_STATUS E ON P.PF_CODE = E.PF_CODE
WHERE E.SURVEY_YEAR = 2020
GROUP BY SURVEY_YEAR, P.PF_CODE
UNION
SELECT
    SURVEY_YEAR AS SV_YEAR,
    PF_NAME AS PREFECTURE,
    "HIGH" AS KIND,
    SUM(HIGH) AS AMT, P.PF_CODE
FROM 
PREFECTURE P LEFT JOIN ENROLLMENT_STATUS E ON P.PF_CODE = E.PF_CODE
WHERE E.SURVEY_YEAR = 2020
GROUP BY SURVEY_YEAR, P.PF_CODE
UNION
SELECT
    SURVEY_YEAR AS SV_YEAR,
    PF_NAME AS PREFECTURE,
    "JUNIOR_CLG" AS KIND,
    SUM(JUNIOR_CLG) AS AMT, P.PF_CODE
FROM 
PREFECTURE P LEFT JOIN ENROLLMENT_STATUS E ON P.PF_CODE = E.PF_CODE
WHERE E.SURVEY_YEAR = 2020
GROUP BY SURVEY_YEAR, P.PF_CODE
UNION
SELECT
    SURVEY_YEAR AS SV_YEAR,
    PF_NAME AS PREFECTURE,
    "COLLEGE" AS KIND,
    SUM(COLLEGE) AS AMT, P.PF_CODE
FROM 
PREFECTURE P LEFT JOIN ENROLLMENT_STATUS E ON P.PF_CODE = E.PF_CODE
WHERE E.SURVEY_YEAR = 2020
GROUP BY SURVEY_YEAR, P.PF_CODE
UNION
SELECT
    SURVEY_YEAR AS SV_YEAR,
    PF_NAME AS PREFECTURE,
    "GRADUATE" AS KIND,
    SUM(GRADUATE) AS AMT, P.PF_CODE
FROM 
PREFECTURE P LEFT JOIN ENROLLMENT_STATUS E ON P.PF_CODE = E.PF_CODE
WHERE E.SURVEY_YEAR = 2020
GROUP BY SURVEY_YEAR, P.PF_CODE
) t1
ORDER BY PF_CODE ASC, AMT DESC;
提出情報
提出日時2022/09/21 21:28:32
コンテスト第2回 SQLコンテスト
問題就学状況の表示変換
受験者suzuki_osamu
状態 (詳細)WA
(Wrong Answer: 誤答)
メモリ使用量85 MB
メッセージ
テストケース(通過数/総数)
0/2
状態
メモリ使用量
データパターン1
WA
83 MB
データパターン2
WA
85 MB