ソースコード
-- select
--     AGE_NAME as 年齢階層,
--     sum(TARGET_POP_5h) as `5時間未満`,
--     sum(TARGET_POP_5h_6h) as `5時間以上6時間未満`,
--     sum(TARGET_POP_6h_7h) as `6時間以上7時間未満`,
--     sum(TARGET_POP_7h_8h) as `7時間以上8時間未満`,
--     sum(TARGET_POP_8h_9h) as `8時間以上9時間未満`,
--     sum(TARGET_POP_9h) as `9時間以上`,
--     sum(TARGET_POP_UNKNOWN) as `不祥`
-- from
--     SLEEP_TIME_DTL
-- inner join
--     AGE_GRP
-- using(AGE_CODE)
-- inner join
--     (
--         select
--             AGE_CODE,
--             sum(TARGET_POP) as TARGET_POP_5h
--         from
--             SLEEP_TIME_DTL
--         where
--             TIME_CODE = 120
--         group by
--             AGE_CODE
--     ) as AG_SLEEP_TIME_DTL_5h
-- using(AGE_CODE)
-- inner join
--     (
--         select
--             AGE_CODE,
--             sum(TARGET_POP) as TARGET_POP_5h_6h
--         from
--             SLEEP_TIME_DTL
--         where
--             TIME_CODE = 130
--         group by
--             AGE_CODE
--     ) as AG_SLEEP_TIME_DTL_5h_6h
-- using(AGE_CODE)
-- inner join
--     (
--         select
--             AGE_CODE,
--             sum(TARGET_POP) as TARGET_POP)_6h_7h
--         from
--             SLEEP_TIME_DTL
--         where
--             TIME_CODE = 140
--         group by
--             AGE_CODE
--     ) as AG_SLEEP_TIME_DTL_6h_7h
-- using(AGE_CODE)
-- inner join
--     (
--         select
--             AGE_CODE,
--             sum(TARGET_POP) as TARGET_POP_7h_8h
--         from
--             SLEEP_TIME_DTL
--         where
--             TIME_CODE = 150
--         group by
--             AGE_CODE
--     ) as AG_SLEEP_TIME_DTL_7h_8h
-- using(AGE_CODE)
-- inner join
--     (
--         select
--             AGE_CODE,
--             sum(TARGET_POP) as TARGET_POP_8h_9h
--         from
--             SLEEP_TIME_DTL
--         where
--             TIME_CODE = 160
--         group by
--             AGE_CODE
--     ) as AG_SLEEP_TIME_DTL_8h_9h
-- using(AGE_CODE)
-- inner join
--     (
--         select
--             AGE_CODE,
--             sum(TARGET_POP) as TARGET_POP_9h
--         from
--             SLEEP_TIME_DTL
--         where
--             TIME_CODE = 170
--         group by
--             AGE_CODE
--     ) as AG_SLEEP_TIME_DTL_9h
-- using(AGE_CODE)
-- inner join
--     (
--         select
--             AGE_CODE,
--             sum(TARGET_POP) as TARGET_POP_UNKNOWN
--         from
--             SLEEP_TIME_DTL
--         where
--             TIME_CODE = 180
--         group by
--             AGE_CODE
--     ) as AG_SLEEP_TIME_DTL_UNKNOWN
-- using(AGE_CODE)
-- group by 年齢階層
select
    AGE_NAME as 年齢階層,
    TARGET_POP_5h as `5時間未満`,
    TARGET_POP_5h_6h as `5時間以上6時間未満`,
    TARGET_POP_6h_7h as `6時間以上7時間未満`,
    TARGET_POP_7h_8h as `7時間以上8時間未満`,
    TARGET_POP_8h_9h as `8時間以上9時間未満`,
    TARGET_POP_9h as `9時間以上`,
    TARGET_POP_UNKNOWN as `不祥`
from
    AGE_GRP
inner join
    (
        select
            AGE_CODE,
            sum(TARGET_POP) as TARGET_POP_5h
        from
            SLEEP_TIME_DTL
        where
            TIME_CODE = 120
        group by
            AGE_CODE
    ) as AG_SLEEP_TIME_DTL_5h
using(AGE_CODE)
inner join
    (
        select
            AGE_CODE,
            sum(TARGET_POP) as TARGET_POP_5h_6h
        from
            SLEEP_TIME_DTL
        where
            TIME_CODE = 130
        group by
            AGE_CODE
    ) as AG_SLEEP_TIME_DTL_5h_6h
using(AGE_CODE)
inner join
    (
        select
            AGE_CODE,
            sum(TARGET_POP) as TARGET_POP_6h_7h
        from
            SLEEP_TIME_DTL
        where
            TIME_CODE = 140
        group by
            AGE_CODE
    ) as AG_SLEEP_TIME_DTL_6h_7h
using(AGE_CODE)
inner join
    (
        select
            AGE_CODE,
            sum(TARGET_POP) as TARGET_POP_7h_8h
        from
            SLEEP_TIME_DTL
        where
            TIME_CODE = 150
        group by
            AGE_CODE
    ) as AG_SLEEP_TIME_DTL_7h_8h
using(AGE_CODE)
inner join
    (
        select
            AGE_CODE,
            sum(TARGET_POP) as TARGET_POP_8h_9h
        from
            SLEEP_TIME_DTL
        where
            TIME_CODE = 160
        group by
            AGE_CODE
    ) as AG_SLEEP_TIME_DTL_8h_9h
using(AGE_CODE)
inner join
    (
        select
            AGE_CODE,
            sum(TARGET_POP) as TARGET_POP_9h
        from
            SLEEP_TIME_DTL
        where
            TIME_CODE = 170
        group by
            AGE_CODE
    ) as AG_SLEEP_TIME_DTL_9h
using(AGE_CODE)
inner join
    (
        select
            AGE_CODE,
            sum(TARGET_POP) as TARGET_POP_UNKNOWN
        from
            SLEEP_TIME_DTL
        where
            TIME_CODE = 180
        group by
            AGE_CODE
    ) as AG_SLEEP_TIME_DTL_UNKNOWN
using(AGE_CODE)
提出情報
提出日時2023/06/12 18:56:19
コンテスト練習用コンテスト
問題年齢別睡眠時間分析
受験者pon-taro
状態 (詳細)WA
(Wrong Answer: 誤答)
メモリ使用量81 MB
メッセージ
テストケース(通過数/総数)
0/2
状態
メモリ使用量
データパターン1
WA
81 MB
データパターン2
WA
77 MB