ソースコード
SELECT
  AGE_NAME AS '年齢階層',
  SUM(sum120) AS '5時間未満',
  SUM(sum130) AS '5時間以上6時間未満',
  SUM(sum140) AS '6時間以上7時間未満',
  SUM(sum150) AS '7時間以上8時間未満',
  SUM(sum160) AS '8時間以上9時間未満',
  SUM(sum170) AS '9時間以上',
  SUM(sum180) AS '不詳'
FROM (
  SELECT
    AGE_NAME,
    dtl.AGE_CODE,
    SUM(CASE WHEN dtl.TIME_CODE = 120 THEN dtl.TARGET_POP ELSE 0 END) AS sum120,
    SUM(CASE WHEN dtl.TIME_CODE = 130 THEN dtl.TARGET_POP ELSE 0 END) AS sum130,
    SUM(CASE WHEN dtl.TIME_CODE = 140 THEN dtl.TARGET_POP ELSE 0 END) AS sum140,
    SUM(CASE WHEN dtl.TIME_CODE = 150 THEN dtl.TARGET_POP ELSE 0 END) AS sum150,
    SUM(CASE WHEN dtl.TIME_CODE = 160 THEN dtl.TARGET_POP ELSE 0 END) AS sum160,
    SUM(CASE WHEN dtl.TIME_CODE = 170 THEN dtl.TARGET_POP ELSE 0 END) AS sum170,
    SUM(CASE WHEN dtl.TIME_CODE = 180 THEN dtl.TARGET_POP ELSE 0 END) AS sum180
  FROM
    SLEEP_TIME_DTL as dtl
    LEFT JOIN AGE_GRP as age
    ON dtl.AGE_CODE = age.AGE_CODE
  GROUP BY dtl.TIME_CODE, dtl.AGE_CODE
)
GROUP BY AGE_CODE
ORDER BY AGE_CODE
    
提出情報
提出日時2022/07/14 10:58:18
コンテスト練習用コンテスト
問題年齢別睡眠時間分析
受験者sh
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量78 MB
メッセージ
テストケース(通過数/総数)
2/2
状態
メモリ使用量
データパターン1
AC
78 MB
データパターン2
AC
76 MB