ソースコード
CREATE TEMPORARY TABLE TMP (
    KIND_ID NUMBER(2)
    ,KIND VARCHAR(10)
);

INSERT INTO TMP(KIND_ID,KIND) VALUES(1,'小学校');
INSERT INTO TMP(KIND_ID,KIND) VALUES(2,'中学校');
INSERT INTO TMP(KIND_ID,KIND) VALUES(3,'高校');
INSERT INTO TMP(KIND_ID,KIND) VALUES(4,'短大');
INSERT INTO TMP(KIND_ID,KIND) VALUES(5,'大学');

WITH PRE AS(
SELECT
    *
FROM PREFECTURE CROSS JOIN TMP)

,ELEMENTARY AS(
    SELECT
        SURVEY_YEAR
        ,PF_CODE
        ,SUM(ELEMENTARY) AS ELE_AMT
    FROM ENROLLMENT_STATUS
    WHERE SURVEY_YEAR = 2020
    GROUP BY SURVEY_YEAR, PF_CODE
)

,MIDDLE AS(
    SELECT
        SURVEY_YEAR
        ,PF_CODE
        ,SUM(MIDDLE) AS MID_AMT
    FROM ENROLLMENT_STATUS
    WHERE SURVEY_YEAR = 2020
    GROUP BY SURVEY_YEAR, PF_CODE
)

,HIGH AS(
    SELECT
        SURVEY_YEAR
        ,PF_CODE
        ,SUM(HIGH) AS HIG_AMT
    FROM ENROLLMENT_STATUS
    WHERE SURVEY_YEAR = 2020
    GROUP BY SURVEY_YEAR, PF_CODE
)

,JUNIOR_CLG AS(
    SELECT
        SURVEY_YEAR
        ,PF_CODE
        ,SUM(JUNIOR_CLG) AS JUN_AMT
    FROM ENROLLMENT_STATUS
    WHERE SURVEY_YEAR = 2020
    GROUP BY SURVEY_YEAR, PF_CODE
)

,COLLEGE AS(
    SELECT
        SURVEY_YEAR
        ,PF_CODE
        ,SUM(COLLEGE) AS COL_AMT
    FROM ENROLLMENT_STATUS
    WHERE SURVEY_YEAR = 2020
    GROUP BY SURVEY_YEAR, PF_CODE
)

SELECT
    SURVEY_YEAR
    ,PF_NAME AS PREFECTURE
    ,KIND
    ,ELE_AMT AS AMT
FROM
(
SELECT *
FROM PRE NATURAL JOIN ELEMENTARY
WHERE KIND = '小学校'
UNION ALL
SELECT *
FROM PRE NATURAL JOIN MIDDLE
WHERE KIND = '中学校'
UNION ALL
SELECT *
FROM PRE NATURAL JOIN HIGH
WHERE KIND = '高校'
UNION ALL
SELECT *
FROM PRE NATURAL JOIN JUNIOR_CLG
WHERE KIND = '短大'
UNION ALL
SELECT *
FROM PRE NATURAL JOIN COLLEGE
WHERE KIND = '大学'
)
WHERE ELE_AMT IS NOT NULL
ORDER BY PF_CODE, KIND_ID;
提出情報
提出日時2023/02/10 16:03:40
コンテスト第2回 SQLコンテスト
問題就学状況の表示変換
受験者mott
状態 (詳細)WA
(Wrong Answer: 誤答)
メモリ使用量80 MB
メッセージ
テストケース(通過数/総数)
0/2
状態
メモリ使用量
データパターン1
WA
80 MB
データパターン2
WA
76 MB