ソースコード
select AGE,GENDER,H_AVG,H_PER,W_AVG,W_PER from 
(
select havg.age                                                        AGE
     , case when havg.gender_code = '30' then 'FEMALE' else 'MALE' end GENDER

     , havg.val                                                        H_AVG
     , round((select 100.0 * cast(sum(case when cast(AVERAGE_VALUE as real) >= havg.val then 1 else 0 end) as real) /
                     cast(count(*) as real)
              from SCHOOL_HEALTH
              where SURVEY_YEAR = 2019
                and CATEGORY_CODE = '10'
                and age = havg.age
                and gender_code = havg.gender_code), 1) || '%'         H_PER
     , wavg.val                                                        W_AVG
     , round((select 100.0 * cast(sum(case when cast(AVERAGE_VALUE as real) >= wavg.val then 1 else 0 end) as real) /
                     cast(count(*) as real)
              from SCHOOL_HEALTH
              where SURVEY_YEAR = 2019
                and CATEGORY_CODE = '20'
                and age = havg.age
                and gender_code = havg.gender_code), 1) || '%'         W_PER
from (select age
           , GENDER_CODE
           , round(avg(AVERAGE_VALUE), 1) as val
      from SCHOOL_HEALTH
      where SURVEY_YEAR = 2019
        and CATEGORY_CODE = '10'
      group by age, GENDER_CODE) havg

     inner join
     (select age
           , GENDER_CODE
           , round(avg(AVERAGE_VALUE), 1) as val
      from SCHOOL_HEALTH
      where SURVEY_YEAR = 2019
        and CATEGORY_CODE = '20'
      group by age, GENDER_CODE) wavg
     on havg.age = wavg.age and
        havg.GENDER_CODE = wavg.GENDER_CODE

order by 1 desc, havg.gender_code desc
    )
提出情報
提出日時2023/08/21 02:19:25
コンテスト第8回 SQLコンテスト
問題身長と体重
受験者tamurakami
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量81 MB
メッセージ
テストケース(通過数/総数)
2/2
状態
メモリ使用量
データパターン1
AC
77 MB
データパターン2
AC
81 MB