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