ソースコード
select
   HRESUT.AGE as AGE
 , case
     when HRESUT.GENDER_CODE = '20' then 'MALE'
     else 'FEMALE'
     end as GENDER
 , HRESUT.HAVE as H_AVG
 , HRESUT.HPER as H_PER
 , WRESUT.WAVE as W_AVG
 , WRESUT.WPER as W_PER
from
(select 
   H.AGE
 , H.GENDER_CODE
 , HAV.HAVE
 , count(*)
 , HAV.HCNT
 , round((count(*) * 100.0 / HAV.HCNT) , 1) || '%'as HPER
from
   (select *
    from SCHOOL_HEALTH
    where CATEGORY_CODE = '10'
      and SURVEY_YEAR = '2019') as H
 , (select
       AGE
     , GENDER_CODE
     , round(avg(AVERAGE_VALUE), 1) as HAVE
     , count(*) as HCNT
    from SCHOOL_HEALTH
    where CATEGORY_CODE = '10'
      and SURVEY_YEAR = '2019'
    group by
       AGE
     , GENDER_CODE) HAV
where
     H.AGE = HAV.AGE
 and H.GENDER_CODE = HAV.GENDER_CODE
 and H.AVERAGE_VALUE >= HAV.HAVE
group by
   H.AGE
 , H.GENDER_CODE
 , HAV.HAVE
) as HRESUT

,(select 
   W.AGE
 , W.GENDER_CODE
 , WAV.WAVE
 , count(*)
 , WAV.WCNT
 , round((count(*) * 100.0 / WAV.WCNT) , 1) || '%'as WPER
from
   (select *
    from SCHOOL_HEALTH
    where CATEGORY_CODE = '20'
      and SURVEY_YEAR = '2019') as W
 , (select
       AGE
     , GENDER_CODE
     , round(avg(AVERAGE_VALUE), 1) as WAVE
     , count(*) as WCNT
    from SCHOOL_HEALTH
    where CATEGORY_CODE = '20'
      and SURVEY_YEAR = '2019'
    group by
       AGE
     , GENDER_CODE) WAV
where
     W.AGE = WAV.AGE
 and W.GENDER_CODE = WAV.GENDER_CODE
 and W.AVERAGE_VALUE >= WAV.WAVE
group by
   W.AGE
 , W.GENDER_CODE
 , WAV.WAVE
) as WRESUT

where
     HRESUT.GENDER_CODE = WRESUT.GENDER_CODE
 and HRESUT.AGE = WRESUT.AGE
order by
   HRESUT.AGE desc
 , HRESUT.GENDER_CODE desc;
提出情報
提出日時2023/08/19 20:54:28
コンテスト第8回 SQLコンテスト
問題身長と体重
受験者udy
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量82 MB
メッセージ
テストケース(通過数/総数)
2/2
状態
メモリ使用量
データパターン1
AC
77 MB
データパターン2
AC
82 MB