ソースコード

WITH PERSON_NUMS AS (
  SELECT
    "総数" AS PERSON,
    0 AS NUM
  UNION SELECT "1人", 1
  UNION SELECT "2人", 2
  UNION SELECT "3人", 3
  UNION SELECT "4人", 4
  UNION SELECT "5人", 5
  UNION SELECT "6人以上", 6
),
JOINDATA AS (
  SELECT
    CLASS_CODE,
    MAX(AMT * 10 + NUM) / 10 AS AMT,
    MAX(AMT * 10 + NUM) % 10 AS NUM
  FROM
    HOUSEHOLD 
    LEFT JOIN PERSON_NUMS ON HOUSEHOLD.PERSON_NAME = PERSON_NUMS.PERSON
  WHERE
    PERSON_CODE != 1
    AND CLASS_CODE != '01'
  GROUP BY
    CLASS_CODE
),
CLASS_CODE_NAME AS (
  SELECT
    CLASS_CODE,
    CLASS_NAME
  FROM
    HOUSEHOLD
  GROUP BY
    CLASS_CODE,
    CLASS_NAME
)

SELECT
  CLASS_NAME AS `CLASS`,
  `PERSON`,
  AMT AS `HOUSEHOLDS`
FROM
  JOINDATA
  LEFT JOIN CLASS_CODE_NAME ON JOINDATA.CLASS_CODE = CLASS_CODE_NAME.CLASS_CODE
  LEFT JOIN PERSON_NUMS ON JOINDATA.NUM = PERSON_NUMS.NUM
ORDER BY
  JOINDATA.CLASS_CODE
提出情報
提出日時2022/10/19 21:13:30
コンテスト第3回 SQLコンテスト
問題最大世帯人員
受験者jf1hnl
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量101 MB
メッセージ
テストケース(通過数/総数)
2/2
状態
メモリ使用量
データパターン1
AC
95 MB
データパターン2
AC
101 MB