ソースコード
with raw as
(
select
    *
from
    ENROLLMENT_STATUS
where
    SURVEY_YEAR = 2020
),
dat as
(
select
    SURVEY_YEAR
    ,PF_CODE
    ,"1.小学校" as "KIND"
    ,ELEMENTARY as "AMT"
from
    raw
union all
select
    SURVEY_YEAR
    ,PF_CODE
    ,"2.中学校" as "KIND"
    ,MIDDLE as "AMT"
from
    raw
union all
select
    SURVEY_YEAR
    ,PF_CODE
    ,"3.高校" as "KIND"
    ,HIGH as "AMT"
from
    raw
union all
select
    SURVEY_YEAR
    ,PF_CODE
    ,"4.短大" as "KIND"
    ,JUNIOR_CLG as "AMT"
from
    raw
union all
select
    SURVEY_YEAR
    ,PF_CODE
    ,"5.大学" as "KIND"
    ,COLLEGE as "AMT"
from
    raw
union all
select
    SURVEY_YEAR
    ,PF_CODE
    ,"6.大学院" as "KIND"
    ,GRADUATE as "AMT"
from
    raw
)


select
    SV_YEAR
    ,PREFECTURE
    ,KIND
    ,AMT
from
    (
    select
        SURVEY_YEAR as SV_YEAR
        ,PF_NAME as PREFECTURE
        ,KIND as KINDwithN
        ,substr(KIND, 3) as KIND
        ,sum(AMT) as AMT
    from
        dat
        left join 
        PREFECTURE
        using(PF_CODE)
    where
        AMT is not null
    group by
        SURVEY_YEAR, PF_CODE, KIND
    order by
        PF_CODE asc, KINDwithN asc
    )


提出情報
提出日時2022/10/18 21:49:01
コンテスト第2回 SQLコンテスト
問題就学状況の表示変換
受験者stkdev
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量78 MB
メッセージ
テストケース(通過数/総数)
2/2
状態
メモリ使用量
データパターン1
AC
78 MB
データパターン2
AC
76 MB