ソースコード
WITH AVG_HEL as (
  SELECT
    AGE,
    GENDER_CODE,
    ROUND(
      AVG(CASE CATEGORY_CODE WHEN 10 THEN AVERAGE_VALUE END)
    ,1) as H_AVG,
    ROUND(
      AVG(CASE CATEGORY_CODE WHEN 20 THEN AVERAGE_VALUE END)
    ,1) as W_AVG
  FROM SCHOOL_HEALTH
  WHERE SURVEY_YEAR = 2019
  GROUP BY AGE,GENDER_CODE
    )
  SELECT
    AVG_HEL.AGE,
    CASE AVG_HEL.GENDER_CODE WHEN 20 THEN 'MALE'  ELSE 'FEMALE' END as GENDER,
    MAX(AVG_HEL.H_AVG) as H_AVG,
    ROUND(100* COUNT(CASE WHEN SH.CATEGORY_CODE = 10 AND H_AVG <= SH.AVERAGE_VALUE THEN 1 END) / COUNT(CASE WHEN SH.CATEGORY_CODE = 10 THEN 1 END),1)  || '%' as H_PER,
    MAX(AVG_HEL.W_AVG) as W_AVG,
    ROUND(100* COUNT(CASE WHEN SH.CATEGORY_CODE = 20 AND W_AVG <= SH.AVERAGE_VALUE THEN 1 END) / COUNT(CASE WHEN SH.CATEGORY_CODE = 20 THEN 1 END),1)  || '%' as W_PER
  FROM AVG_HEL 
  LEFT OUTER JOIN SCHOOL_HEALTH SH
  ON AVG_HEL.AGE = SH.AGE
  AND AVG_HEL.GENDER_CODE = SH.GENDER_CODE
  AND SURVEY_YEAR = 2019 
  GROUP BY AVG_HEL.AGE,AVG_HEL.GENDER_CODE
  ORDER BY AVG_HEL.AGE desc,AVG_HEL.GENDER_CODE desc
提出情報
提出日時2023/08/21 17:00:32
コンテスト第8回 SQLコンテスト
問題身長と体重
受験者110047
状態 (詳細)WA
(Wrong Answer: 誤答)
メモリ使用量82 MB
メッセージ
テストケース(通過数/総数)
0/2
状態
メモリ使用量
データパターン1
WA
78 MB
データパターン2
WA
82 MB