ソースコード
SELECT
    SV_YEAR
,   PF_NAME
,   KIND
,   AMT
FROM
(

SELECT
    SURVEY_YEAR AS SV_YEAR
,   PREFECTURE.PF_NAME AS PF_NAME
,   '小学校' AS KIND
,   SUM( ELEMENTARY ) AS AMT
,   1 AS SORT_NO
FROM
    ENROLLMENT_STATUS
INNER JOIN
    PREFECTURE
ON  ENROLLMENT_STATUS.PF_CODE   = PREFECTURE.PF_CODE
WHERE
    SURVEY_YEAR     = '2020'
AND ELEMENTARY      IS NOT NULL
GROUP BY
    PREFECTURE.PF_CODE
UNION
SELECT
    SURVEY_YEAR AS SV_YEAR
,   PREFECTURE.PF_NAME AS PF_NAME
,   '中学校' AS KIND
,   SUM( MIDDLE ) AS AMT
,   2 AS SORT_NO
FROM
    ENROLLMENT_STATUS
INNER JOIN
    PREFECTURE
ON  ENROLLMENT_STATUS.PF_CODE   = PREFECTURE.PF_CODE
WHERE
    SURVEY_YEAR     = '2020'
AND MIDDLE      IS NOT NULL
GROUP BY
    PREFECTURE.PF_CODE
UNION
SELECT
    SURVEY_YEAR AS SV_YEAR
,   PREFECTURE.PF_NAME AS PF_NAME
,   '高校' AS KIND
,   SUM( HIGH ) AS AMT
,   3 AS SORT_NO
FROM
    ENROLLMENT_STATUS
INNER JOIN
    PREFECTURE
ON  ENROLLMENT_STATUS.PF_CODE   = PREFECTURE.PF_CODE
WHERE
    SURVEY_YEAR     = '2020'
AND HIGH      IS NOT NULL
GROUP BY
    PREFECTURE.PF_CODE
UNION
SELECT
    SURVEY_YEAR AS SV_YEAR
,   PREFECTURE.PF_NAME AS PF_NAME
,   '短大' AS KIND
,   SUM( JUNIOR_CLG ) AS AMT
,   4 AS SORT_NO
FROM
    ENROLLMENT_STATUS
INNER JOIN
    PREFECTURE
ON  ENROLLMENT_STATUS.PF_CODE   = PREFECTURE.PF_CODE
WHERE
    SURVEY_YEAR     = '2020'
AND JUNIOR_CLG      IS NOT NULL
GROUP BY
    PREFECTURE.PF_CODE
UNION
SELECT
    SURVEY_YEAR AS SV_YEAR
,   PREFECTURE.PF_NAME AS PF_NAME
,   '大学' AS KIND
,   SUM( COLLEGE ) AS AMT
,   5 AS SORT_NO
FROM
    ENROLLMENT_STATUS
INNER JOIN
    PREFECTURE
ON  ENROLLMENT_STATUS.PF_CODE   = PREFECTURE.PF_CODE
WHERE
    SURVEY_YEAR     = '2020'
AND COLLEGE      IS NOT NULL
GROUP BY
    PREFECTURE.PF_CODE
UNION
SELECT
    SURVEY_YEAR AS SV_YEAR
,   PREFECTURE.PF_NAME AS PF_NAME
,   '大学院' AS KIND
,   SUM( GRADUATE ) AS AMT
,   6 AS SORT_NO
FROM
    ENROLLMENT_STATUS
INNER JOIN
    PREFECTURE
ON  ENROLLMENT_STATUS.PF_CODE   = PREFECTURE.PF_CODE
WHERE
    SURVEY_YEAR     = '2020'
AND GRADUATE      IS NOT NULL
GROUP BY
    PREFECTURE.PF_CODE
ORDER BY
    PF_CODE ASC
,   SORT_NO ASC
)
提出情報
提出日時2022/09/21 15:33:01
コンテスト第2回 SQLコンテスト
問題就学状況の表示変換
受験者hiroaki.kine
状態 (詳細)RE
(Runtime Error: 実行時エラー)
メモリ使用量93 MB
メッセージ
SQLITE_ERROR: 1st ORDER BY term does not match any column in the result set
テストケース(通過数/総数)
0/2
状態
メモリ使用量
データパターン1
RE
93 MB
データパターン2
RE
93 MB