ソースコード
select SB.AGE
, SB.GENDER

, SB.H_AVG
, round(cast((select count(*)
   from SCHOOL_HEALTH SH
   where  SH.AGE = SB.AGE
   and SH.SURVEY_YEAR = SB.SURVEY_YEAR
   and SH.GENDER_CODE = SB.GENDER_CODE
   and SH.CATEGORY_CODE = '10'
   and SH.AVERAGE_VALUE >= SB.H_AVG
   ) as REAL)
   /SB.H_CNT*100,1) || '%' H_PER

, SB.W_AVG
, round(cast((select count(*)
   from SCHOOL_HEALTH SW
   where  SW.AGE = SB.AGE
   and SW.SURVEY_YEAR = SB.SURVEY_YEAR
   and SW.GENDER_CODE = SB.GENDER_CODE
   and SW.CATEGORY_CODE = '20'
   and SW.AVERAGE_VALUE >= SB.W_AVG
   ) as REAL)
   /SB.W_CNT*100,1) || '%' W_PER

from (

select
  S.AGE
, S.GENDER_CODE
, case when S.GENDER_CODE = '20' then 'MALE' else 'FEMALE' end GENDER
, S.SURVEY_YEAR
, sum(case when S.CATEGORY_CODE = '10' then 1 else null end) H_CNT
, round(avg(case when S.CATEGORY_CODE = '10' then S.AVERAGE_VALUE else null end), 1) H_AVG
, sum(case when S.CATEGORY_CODE = '20' then 1 else null end) W_CNT
, round(avg(case when S.CATEGORY_CODE = '20' then S.AVERAGE_VALUE else null end), 1) W_AVG
from SCHOOL_HEALTH S
where S.SURVEY_YEAR = 2019
group by
  S.AGE
, S.GENDER_CODE

    ) SB

group by
 SB.AGE
, SB.GENDER

order by 
  SB.AGE desc
, SB.GENDER_CODE desc
提出情報
提出日時2023/10/15 14:08:53
コンテスト第8回 SQLコンテスト
問題身長と体重
受験者kiharu
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量87 MB
メッセージ
テストケース(通過数/総数)
2/2
状態
メモリ使用量
データパターン1
AC
83 MB
データパターン2
AC
87 MB