ソースコード
select a.SV_YEAR, a.PREFECTURE, a.KIND, a.AMT from
(
select
    ENROLLMENT_STATUS.PF_CODE,
    ENROLLMENT_STATUS.SURVEY_YEAR as SV_YEAR,
    PREFECTURE.PF_NAME as PREFECTURE,
    '小学校' as KIND,
    sum(ENROLLMENT_STATUS.ELEMENTARY) as AMT
from ENROLLMENT_STATUS
    left join PREFECTURE on PREFECTURE.PF_CODE = ENROLLMENT_STATUS.PF_CODE
    where SURVEY_YEAR = 2020
    group by ENROLLMENT_STATUS.PF_CODE
union all
select
    ENROLLMENT_STATUS.PF_CODE,
    ENROLLMENT_STATUS.SURVEY_YEAR as SV_YEAR,
    PREFECTURE.PF_NAME as PREFECTURE,
    '中学校' as KIND,
    sum(ENROLLMENT_STATUS.MIDDLE) as AMT
from ENROLLMENT_STATUS
    left join PREFECTURE on PREFECTURE.PF_CODE = ENROLLMENT_STATUS.PF_CODE
    where SURVEY_YEAR = 2020
    group by ENROLLMENT_STATUS.PF_CODE
union all
select
    ENROLLMENT_STATUS.PF_CODE,
    ENROLLMENT_STATUS.SURVEY_YEAR as SV_YEAR,
    PREFECTURE.PF_NAME as PREFECTURE,
    '高校' as KIND,
    sum(ENROLLMENT_STATUS.HIGH) as AMT
from ENROLLMENT_STATUS
    left join PREFECTURE on PREFECTURE.PF_CODE = ENROLLMENT_STATUS.PF_CODE
    where SURVEY_YEAR = 2020
    group by ENROLLMENT_STATUS.PF_CODE
union all
select
    ENROLLMENT_STATUS.PF_CODE,
    ENROLLMENT_STATUS.SURVEY_YEAR as SV_YEAR,
    PREFECTURE.PF_NAME as PREFECTURE,
    '短大' as KIND,
    sum(ENROLLMENT_STATUS.JUNIOR_CLG) as AMT
from ENROLLMENT_STATUS
    left join PREFECTURE on PREFECTURE.PF_CODE = ENROLLMENT_STATUS.PF_CODE
    where SURVEY_YEAR = 2020
    group by ENROLLMENT_STATUS.PF_CODE
union all
select
    ENROLLMENT_STATUS.PF_CODE,
    ENROLLMENT_STATUS.SURVEY_YEAR as SV_YEAR,
    PREFECTURE.PF_NAME as PREFECTURE,
    '大学' as KIND,
    sum(ENROLLMENT_STATUS.COLLEGE) as AMT
from ENROLLMENT_STATUS
    left join PREFECTURE on PREFECTURE.PF_CODE = ENROLLMENT_STATUS.PF_CODE
    where SURVEY_YEAR = 2020
    group by ENROLLMENT_STATUS.PF_CODE
union all
select
    ENROLLMENT_STATUS.PF_CODE,
    ENROLLMENT_STATUS.SURVEY_YEAR as SV_YEAR,
    PREFECTURE.PF_NAME as PREFECTURE,
    '大学院' as KIND,
    sum(ENROLLMENT_STATUS.GRADUATE) as AMT
from ENROLLMENT_STATUS
    left join PREFECTURE on PREFECTURE.PF_CODE = ENROLLMENT_STATUS.PF_CODE
    where SURVEY_YEAR = 2020
    group by ENROLLMENT_STATUS.PF_CODE
) as a
where AMT is not NULL
order by a.PF_CODE asc;
提出情報
提出日時2022/09/22 12:03:35
コンテスト第2回 SQLコンテスト
問題就学状況の表示変換
受験者chimayu
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量97 MB
メッセージ
テストケース(通過数/総数)
2/2
状態
メモリ使用量
データパターン1
AC
97 MB
データパターン2
AC
96 MB