ソースコード
WITH SCHOOLS_TBL AS (
    SELECT
        1 AS SCHOOL
    UNION ALL
    SELECT
        SCHOOL + 1
    FROM
        SCHOOLS_TBL
    WHERE
        SCHOOL < 6
)
SELECT
    T.SURVEY_YEAR AS SV_YEAR,
    P.PF_NAME AS PREFECTURE,
    T.SCHOOL_LVL AS KIND,
    SUM(T.SCHOOL_AMT) AS AMT
FROM (
SELECT
    E.SURVEY_YEAR,
    E.PF_CODE,
    S.SCHOOL,
    CASE S.SCHOOL
        WHEN 1 THEN '小学校'
        WHEN 2 THEN '中学校'
        WHEN 3 THEN '高校'
        WHEN 4 THEN '短大'
        WHEN 5 THEN '大学'
        WHEN 6 THEN '大学院'
    END AS SCHOOL_LVL,
    CASE S.SCHOOL
        WHEN 1 THEN E.ELEMENTARY
        WHEN 2 THEN E.MIDDLE
        WHEN 3 THEN E.HIGH
        WHEN 4 THEN E.JUNIOR_CLG
        WHEN 5 THEN E.COLLEGE
        WHEN 6 THEN E.GRADUATE
    END AS SCHOOL_AMT
FROM
    ENROLLMENT_STATUS E
CROSS JOIN
    SCHOOLS_TBL S
WHERE
    E.SURVEY_YEAR = '2020'
) T
LEFT OUTER JOIN PREFECTURE P
ON T.PF_CODE = P.PF_CODE
WHERE
    T.SCHOOL_AMT IS NOT NULL
GROUP BY
    T.SURVEY_YEAR,
    P.PF_NAME,
    T.SCHOOL_LVL
ORDER BY
    P.PF_CODE ASC,
    T.SCHOOL ASC
提出情報
提出日時2023/02/22 17:45:46
コンテスト第2回 SQLコンテスト
問題就学状況の表示変換
受験者daidai07
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量90 MB
メッセージ
テストケース(通過数/総数)
2/2
状態
メモリ使用量
データパターン1
AC
90 MB
データパターン2
AC
86 MB