ソースコード
select g.AGE AGE,g.GENDER GENDER,g.H_AVG H_AVG,g.H_PER H_PER,h.H_AVG W_AVG,h.H_PER W_PER
from
 ( select a.AGE AGE,(case a.GENDER_CODE when '20' then 'MALE' else 'FEMALE' end ) as GENDER, a.H_AVG H_AVG,  ROUND(b.AVERAGE_VALUE_OVER*100.0 /c.AVERAGE_VALUE_TOTAL,1)||'%' H_PER
from 
(
   select ROUND(AVG(AVERAGE_VALUE),1) H_AVG,CATEGORY_CODE,GENDER_CODE,AGE
   from SCHOOL_HEALTH
   where CATEGORY_CODE='10' and SURVEY_YEAR=2019
   group by CATEGORY_CODE,GENDER_CODE,AGE
) a,
(
   select COUNT(1) AVERAGE_VALUE_OVER,e.CATEGORY_CODE,e.GENDER_CODE,e.AGE
   from SCHOOL_HEALTH e,
   (
    select ROUND(AVG(AVERAGE_VALUE),2) AVG_VALUE,CATEGORY_CODE,GENDER_CODE,AGE
    from SCHOOL_HEALTH
     where CATEGORY_CODE='10' and SURVEY_YEAR=2019 
     group by CATEGORY_CODE,GENDER_CODE,AGE
   )d
   where e.CATEGORY_CODE='10' and e.SURVEY_YEAR=2019 
   and d.CATEGORY_CODE= e.CATEGORY_CODE and d.GENDER_CODE=e.GENDER_CODE and d.AGE=e.AGE
   and d.AVG_VALUE<=e.AVERAGE_VALUE
   group by e.CATEGORY_CODE,e.GENDER_CODE,e.AGE

) b,
(
   select COUNT(AVERAGE_VALUE) AVERAGE_VALUE_TOTAL,CATEGORY_CODE,GENDER_CODE,AGE
   from SCHOOL_HEALTH
   where CATEGORY_CODE='10' and SURVEY_YEAR=2019
   group by CATEGORY_CODE,GENDER_CODE,AGE
) c
where a.CATEGORY_CODE=b.CATEGORY_CODE 
and a.AGE= b.AGE
and a.GENDER_CODE=b.GENDER_CODE
and a.CATEGORY_CODE=c.CATEGORY_CODE 
and a.AGE= c.AGE
and a.GENDER_CODE=c.GENDER_CODE
 ) g
,
(
select a.AGE AGE,(case a.GENDER_CODE when '20' then 'MALE' else 'FEMALE' end ) as GENDER, a.H_AVG H_AVG,  ROUND(b.AVERAGE_VALUE_OVER*100.0 /c.AVERAGE_VALUE_TOTAL,1)||'%' H_PER
from 
(
   select ROUND(AVG(AVERAGE_VALUE),1) H_AVG,CATEGORY_CODE,GENDER_CODE,AGE
   from SCHOOL_HEALTH
   where CATEGORY_CODE='20' and SURVEY_YEAR=2019
   group by CATEGORY_CODE,GENDER_CODE,AGE
) a,
(
   select COUNT(1) AVERAGE_VALUE_OVER,e.CATEGORY_CODE,e.GENDER_CODE,e.AGE
   from SCHOOL_HEALTH e,
   (
    select ROUND(AVG(AVERAGE_VALUE),2) AVG_VALUE,CATEGORY_CODE,GENDER_CODE,AGE
    from SCHOOL_HEALTH
     where CATEGORY_CODE='20' and SURVEY_YEAR=2019 
     group by CATEGORY_CODE,GENDER_CODE,AGE
   )d
   where e.CATEGORY_CODE='20' and e.SURVEY_YEAR=2019 
   and d.CATEGORY_CODE= e.CATEGORY_CODE and d.GENDER_CODE=e.GENDER_CODE and d.AGE=e.AGE
   and d.AVG_VALUE<=e.AVERAGE_VALUE
   group by e.CATEGORY_CODE,e.GENDER_CODE,e.AGE

) b,
(
   select COUNT(AVERAGE_VALUE) AVERAGE_VALUE_TOTAL,CATEGORY_CODE,GENDER_CODE,AGE
   from SCHOOL_HEALTH
   where CATEGORY_CODE='20' and SURVEY_YEAR=2019
   group by CATEGORY_CODE,GENDER_CODE,AGE
) c
where a.CATEGORY_CODE=b.CATEGORY_CODE 
and a.AGE= b.AGE
and a.GENDER_CODE=b.GENDER_CODE
and a.CATEGORY_CODE=c.CATEGORY_CODE 
and a.AGE= c.AGE
and a.GENDER_CODE=c.GENDER_CODE

 ) h
 where g.AGE= h.AGE and g.GENDER= h.GENDER

order by AGE desc,GENDER asc
提出情報
提出日時2023/08/19 01:08:46
コンテスト第8回 SQLコンテスト
問題身長と体重
受験者goudezhao
状態 (詳細)WA
(Wrong Answer: 誤答)
メモリ使用量82 MB
メッセージ
テストケース(通過数/総数)
0/2
状態
メモリ使用量
データパターン1
WA
78 MB
データパターン2
WA
82 MB