ソースコード
/*
select
    all.AGE_CODE as "年齢コード",
    all.AGE_NAME as "年齢階層名",
    sum(all.SP_TIME_5) as "5時間未満",
    sum(all.SP_TIME_6) as "5時間以上6時間未満",
    sum(all.SP_TIME_7) as "6時間以上7時間未満",
    sum(all.SP_TIME_8) as "7時間以上8時間未満",
    sum(all.SP_TIME_9) as "8時間以上9時間未満",
    sum(all.SP_TIME_9OVER) as "9時間以上"
FROM
    ((SLEEP_TIME_DTL as s
        INNER JOIN AGE_GRP as g ON s.AGE_CODE=g.AGE_CODE) as s2
        INNER JOIN PREFECTURE as p ON s2.PF_CODE=p.PF_CODE) as all
WHERE
    all.PF_NAME in ('北海道', '青森県', '岩手県', '宮城県', '福島県')
GROUP BY
    all.AGE_CODE
ORDER BY
    all.AGE_CODE;

SELECT
    mk2.AGE_CODE as '年齢コード', 
    mk2.AGE_NAME as '年齢階層名', 
    SUM(mk2.SP_TIME_5) as '5時間未満',
    SUM(mk2.SP_TIME_6) as '5時間以上6時間未満',
    SUM(mk2.SP_TIME_7) as '6時間以上7時間未満',
    SUM(mk2.SP_TIME_8) as '7時間以上8時間未満',
    SUM(mk2.SP_TIME_9) as '8時間以上9時間未満',
    SUM(mk2.SP_TIME_9OVER) as'9時間以上' 
FROM
    ((SLEEP_TIME_DTL as sld
    INNER JOIN AGE_GRP as ag ON sld.AGE_CODE=ag.AGE_CODE) as mk
    INNER JOIN PREFECTURE as p ON mk.PF_CODE=p.PF_CODE) as mk2
WHERE
    mk2.PF_NAME in ('北海道', '青森県', '岩手県', '宮城県', '福島県')
GROUP BY
    mk2.AGE_CODE
ORDER BY
    mk2.AGE_CODE;

select
    mk2.AGE_CODE,
    mk2.AGE_NAME as "年齢階層名",
    sum(mk2.SP_TIME_5) as "5時間未満",
    SUM(mk2.SP_TIME_6) as "5時間以上6時間未満",
    SUM(mk2.SP_TIME_7) as "6時間以上7時間未満",
    SUM(mk2.SP_TIME_8) as "7時間以上8時間未満",
    SUM(mk2.SP_TIME_9) as "8時間以上9時間未満",
    SUM(mk2.SP_TIME_9OVER) as"9時間以上"
from
    ((SLEEP_TIME_DTL as sld
    inner join AGE_GRP as ag on sld.AGE_CODE=ag.AGE_CODE) as mk
    inner join PREFECTURE as p on mk.PF_CODE=p.PF_CODE) as mk2
where
    mk2.PF_NAME in ('北海道', '青森県', '岩手県', '宮城県', '福島県')
group by
    mk2.AGE_CODE
order by
    mk2.AGE_CODE;
*/
select
    ag.AGE_CODE as "年齢コード",
    ag.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
    ((SLEEP_TIME_DTL as sld
    inner join AGE_GRP as ag on sld.AGE_CODE=ag.AGE_CODE)
    inner join PREFECTURE as p on sld.PF_CODE=p.PF_CODE)
where
    PF_NAME in ('北海道', '青森県', '岩手県', '宮城県', '福島県')
group by
    ag.AGE_CODE
order by
    ag.AGE_CODE
提出情報
提出日時2022/07/21 03:48:09
コンテスト第1回 SQLコンテスト
問題睡眠時間帯別集計
受験者mbo57
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量76 MB
メッセージ
テストケース(通過数/総数)
2/2
状態
メモリ使用量
データパターン1
AC
76 MB
データパターン2
AC
75 MB