ソースコード
WITH AVG AS(
    SELECT
    GENDER_CODE,
    AGE,
    ROUND(AVG(CASE WHEN CATEGORY_CODE = '10' THEN AVERAGE_VALUE END), 1) HAVG,
    ROUND(AVG(CASE WHEN CATEGORY_CODE = '20' THEN AVERAGE_VALUE END), 1) WAVG
    FROM SCHOOL_HEALTH
    WHERE SURVEY_YEAR = '2019'
    GROUP BY AGE,GENDER_CODE
  )
  
SELECT
SH.AGE AGE,
CASE WHEN SH.GENDER_CODE = '20' THEN 'MALE' WHEN SH.GENDER_CODE = '30' THEN 'FEMALE' END AS GENDER,
HAVG H_AVG,
ROUND(100.0 * COUNT(CASE WHEN SH.CATEGORY_CODE = '10' AND SH.AVERAGE_VALUE >= AVG.HAVG THEN 1 END)/
COUNT(CASE WHEN SH.CATEGORY_CODE = '10' THEN 1 END),1) || '%'
AS H_PER,
WAVG W_AVG,
ROUND(100.0 * COUNT(CASE WHEN SH.CATEGORY_CODE = '20' AND SH.AVERAGE_VALUE >= AVG.WAVG THEN 1 END)/
COUNT(CASE WHEN SH.CATEGORY_CODE = '20' THEN 1 END),1) || '%'
AS W_PER
FROM AVG
LEFT JOIN SCHOOL_HEALTH SH ON AVG.AGE=SH.AGE  
AND AVG.GENDER_CODE = SH.GENDER_CODE
AND SURVEY_YEAR = '2019'
GROUP BY SH.AGE,SH.GENDER_CODE
ORDER BY SH.AGE DESC
,SH.GENDER_CODE DESC
提出情報
提出日時2024/07/19 17:11:23
コンテスト第8回 SQLコンテスト
問題身長と体重
受験者0014
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量87 MB
メッセージ
テストケース(通過数/総数)
2/2
状態
メモリ使用量
データパターン1
AC
85 MB
データパターン2
AC
87 MB