ソースコード
WITH
    four AS (
        SELECT AGE_CODE, SUM(TARGET_POP) AS result
        FROM SLEEP_TIME_DTL
        WHERE TIME_CODE = 120
        GROUP BY AGE_CODE
    ),
    five AS (
        SELECT AGE_CODE, SUM(TARGET_POP) AS result
        FROM SLEEP_TIME_DTL
        WHERE TIME_CODE = 130
        GROUP BY AGE_CODE
    ),
    six AS (
        SELECT AGE_CODE, SUM(TARGET_POP) AS result
        FROM SLEEP_TIME_DTL
        WHERE TIME_CODE = 140
        GROUP BY AGE_CODE
    ),
    seven AS (
        SELECT AGE_CODE, SUM(TARGET_POP) AS result
        FROM SLEEP_TIME_DTL
        WHERE TIME_CODE = 150
        GROUP BY AGE_CODE
    ),
    eight AS (
        SELECT AGE_CODE, SUM(TARGET_POP) AS result
        FROM SLEEP_TIME_DTL
        WHERE TIME_CODE = 160
        GROUP BY AGE_CODE
    ),
    nine AS (
        SELECT AGE_CODE, SUM(TARGET_POP) AS result
        FROM SLEEP_TIME_DTL
        WHERE TIME_CODE = 170
        GROUP BY AGE_CODE
    ),
    ten AS (
        SELECT AGE_CODE, SUM(TARGET_POP) AS result
        FROM SLEEP_TIME_DTL
        WHERE TIME_CODE = 180
        GROUP BY AGE_CODE
    )
SELECT 
    AGE.AGE_NAME AS 年齢階層,
    four.result AS "5時間未満",
    five.result AS "5時間以上6時間未満",
    six.result AS "6時間以上7時間未満",
    seven.result AS "7時間以上8時間未満",
    eight.result AS "8時間以上9時間未満",
    nine.result AS "9時間以上",
    ten.result AS "不詳"
FROM
    SLEEP_TIME_DTL AS DTL
    LEFT JOIN AGE_GRP AS AGE
        ON DTL.AGE_CODE = AGE.AGE_CODE
    LEFT JOIN four
        ON DTL.AGE_CODE = four.AGE_CODE
    LEFT JOIN five
        ON DTL.AGE_CODE = five.AGE_CODE
    LEFT JOIN six
        ON DTL.AGE_CODE = six.AGE_CODE
    LEFT JOIN seven
        ON DTL.AGE_CODE = seven.AGE_CODE
    LEFT JOIN eight
        ON DTL.AGE_CODE = eight.AGE_CODE
    LEFT JOIN nine
        ON DTL.AGE_CODE = nine.AGE_CODE
    LEFT JOIN ten
        ON DTL.AGE_CODE = ten.AGE_CODE
GROUP BY AGE.AGE_CODE
ORDER BY DTL.AGE_CODE ASC;
提出情報
提出日時2022/07/14 15:14:26
コンテスト練習用コンテスト
問題年齢別睡眠時間分析
受験者segawa
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量79 MB
メッセージ
テストケース(通過数/総数)
2/2
状態
メモリ使用量
データパターン1
AC
79 MB
データパターン2
AC
77 MB