コンテストの制限時間が終了しました。
以降も提出を行うことができますが、順位集計には反映されません。
以降も提出を行うことができますが、順位集計には反映されません。
ソースコード
WITH
CTE AS (
SELECT
A.SURVEY_YEAR AS SV_YEAR
, B.PF_CODE AS CODE
, B.PF_NAME AS PREFECTURE
, SUM(A.ELEMENTARY) AS ELEMENTARY
, SUM(A.MIDDLE) AS MIDDLE
, SUM(A.HIGH) AS HIGH
, SUM(A.JUNIOR_CLG) AS JUNIOR_CLG
, SUM(A.COLLEGE) AS COLLEGE
, SUM(A.GRADUATE) AS GRADUATE
FROM
ENROLLMENT_STATUS A
INNER JOIN PREFECTURE B ON A.PF_CODE = B.PF_CODE
WHERE
A.SURVEY_YEAR = 2020
GROUP BY
A.SURVEY_YEAR
, B.PF_NAME
)
SELECT
SV_YEAR
, PREFECTURE
, KIND
, AMT
FROM (
SELECT SV_YEAR, CODE, PREFECTURE, 1 AS KIND_POS, '小学校' AS KIND, ELEMENTARY AS AMT FROM CTE WHERE ELEMENTARY IS NOT NULL UNION ALL
SELECT SV_YEAR, CODE, PREFECTURE, 2 AS KIND_POS, '中学校' AS KIND, MIDDLE AS AMT FROM CTE WHERE MIDDLE IS NOT NULL UNION ALL
SELECT SV_YEAR, CODE, PREFECTURE, 3 AS KIND_POS, '高校' AS KIND, HIGH AS AMT FROM CTE WHERE HIGH IS NOT NULL UNION ALL
SELECT SV_YEAR, CODE, PREFECTURE, 4 AS KIND_POS, '短大' AS KIND, JUNIOR_CLG AS AMT FROM CTE WHERE JUNIOR_CLG IS NOT NULL UNION ALL
SELECT SV_YEAR, CODE, PREFECTURE, 5 AS KIND_POS, '大学' AS KIND, COLLEGE AS AMT FROM CTE WHERE COLLEGE IS NOT NULL UNION ALL
SELECT SV_YEAR, CODE, PREFECTURE, 6 AS KIND_POS, '大学院' AS KIND, GRADUATE AS AMT FROM CTE WHERE GRADUATE IS NOT NULL
)
ORDER BY
CODE ASC
, KIND_POS ASC
提出情報
提出日時 | 2024/11/30 17:19:45 |
コンテスト | 第2回 SQLコンテスト |
問題 | 就学状況の表示変換 |
受験者 | masami.araki |
状態 (詳細) | AC (Accepted: 正答) |
メモリ使用量 | 86 MB |
メッセージ
テストケース(通過数/総数)
2/2
状態
メモリ使用量
データパターン1
AC
86 MB
データパターン2
AC
86 MB