ソースコード
with t0 as 
(
    select 
        *
        from age_grp
)
, t1 as 
(
    select 
        *
        from PREFECTURE
)
, t2 as 
(
    select 
        *
        from SLEEP_TIME_DTL
)
, t3 as 
(
    select 
        pf_code, 
        t2.age_code, 
        age_name, 
        sp_time_5, 
        sp_time_6, 
        sp_time_7, 
        sp_time_8, 
        sp_time_9, 
        sp_time_9over
        from t2
        inner join t0
        on t2.age_code=t0.age_code
)
, t4 as 
(
    select
        t3.pf_code, 
        pf_name, 
        age_code, 
        age_name, 
        sp_time_5, 
        sp_time_6, 
        sp_time_7, 
        sp_time_8, 
        sp_time_9, 
        sp_time_9over
        from t3
        left join t1
        on t3.pf_code=t1.pf_code
)
, t5 as 
(
    select
        pf_name, 
        age_code, 
        age_name, 
        sp_time_5, 
        sp_time_6, 
        sp_time_7, 
        sp_time_8, 
        sp_time_9, 
        sp_time_9over
        from t4
        where pf_name='北海道' or pf_name='青森県' or pf_name='岩手県'
        or pf_name='宮城県' or pf_name='福島県' 
)
, t6 as 
(
    select 
        age_code as 年齢コード, 
        age_name as 年齢階層名, 
        sum(sp_time_5) as '5時間未満', 
        sum(sp_time_6) as '5時間以上6時間未満', 
        sum(sp_time_7) as '6時間以上7時間未満', 
        sum(sp_time_8) as '7時間以上8時間未満', 
        sum(sp_time_9) as '8時間以上9時間未満', 
        sum(sp_time_9over) as '9時間以上'
        from t5
        group by age_code, age_name
        order by age_code
)
select * from t6
提出情報
提出日時2022/07/20 17:53:45
コンテスト第1回 SQLコンテスト
問題睡眠時間帯別集計
受験者otooo
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量104 MB
メッセージ
テストケース(通過数/総数)
2/2
状態
メモリ使用量
データパターン1
AC
102 MB
データパターン2
AC
104 MB