ソースコード
WITH tbl_1 AS (
    SELECT
        SURVEY_YEAR AS SV_YEAR
        ,PF_NAME AS PREFECTURE
        ,SUM(ELEMENTARY) AS 小学校
        ,SUM(MIDDLE) AS 中学校
        ,SUM(HIGH) AS 高校
        ,SUM(JUNIOR_CLG) AS 短大
        ,SUM(COLLEGE) AS 大学
        ,SUM(GRADUATE) AS 大学院
    FROM 
        ENROLLMENT_STATUS AS tbl_e
    INNER JOIN 
	    PREFECTURE AS tbl_p
    ON 
	    tbl_e.PF_CODE = tbl_p.PF_CODE
    WHERE 
        SURVEY_YEAR = 2020
    GROUP BY
        PF_NAME
), tmp_db2 AS ( 
    SELECT 
        SV_YEAR
        ,PREFECTURE
        ,'小学校' AS KIND
        ,小学校 AS AMT
        ,1 AS 'number'
    FROM 
    	tbl_1
    	
    UNION ALL
    SELECT 
        SV_YEAR
        ,PREFECTURE
        ,'中学校' AS KIND
        ,中学校 AS AMT
        ,2 AS 'number'
    FROM 
    	tbl_1
    	
    UNION ALL
    SELECT 
        SV_YEAR
        ,PREFECTURE
        ,'高校' AS KIND
        ,高校 AS AMT
        ,3 AS 'number'
    FROM 
    	tbl_1
    	
    UNION ALL
    SELECT 
        SV_YEAR
        ,PREFECTURE
        ,'短大' AS KIND
        ,短大 AS AMT
        ,4 AS 'number'
    FROM 
    	tbl_1
    	
    UNION ALL
    SELECT 
        SV_YEAR
        ,PREFECTURE
        ,'大学' AS KIND
        ,大学 AS AMT
        ,5 AS 'number'
    FROM 
    	tbl_1
    	
    UNION ALL
    SELECT 
        SV_YEAR
        ,PREFECTURE
        ,'大学院' AS KIND
        ,大学院 AS AMT
        ,6 AS 'number'
    FROM 
    	tbl_1
)
SELECT 
    SV_YEAR
    ,PREFECTURE
    ,KIND
    ,AMT
FROM
    tmp_db2
WHERE 
    AMT IS NOT NULL
ORDER BY
    PREFECTURE
    ,'number';
    
提出情報
提出日時2023/07/12 16:22:52
コンテスト第2回 SQLコンテスト
問題就学状況の表示変換
受験者ykkn_2525
状態 (詳細)WA
(Wrong Answer: 誤答)
メモリ使用量82 MB
メッセージ
テストケース(通過数/総数)
1/2
状態
メモリ使用量
データパターン1
WA
82 MB
データパターン2
AC
79 MB