ソースコード
with avg_tbl as (
    select 
        age
        , gender_code
        , round(avg(case category_code when 10 then average_value end),1) as h_avg
        , round(avg(case category_code when 20 then average_value end),1) as w_avg
    from school_health
    where survey_year=2019
    group by age, gender_code
)
select 
    avg_tbl.age as AGE
    , case avg_tbl.gender_code when 20 then 'MALE' else 'FEMALE' end GENDER
    , max(h_avg) H_AVG
    , max(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 avg_tbl
left join school_health sh on avg_tbl.age=sh.age
                          and avg_tbl.gender_code=sh.gender_code
                          and survey_year=2019
group by avg_tbl.age, avg_tbl.gender_code
order by avg_tbl.age desc, avg_tbl.gender_code desc;
提出情報
提出日時2024/05/13 18:08:49
コンテスト第8回 SQLコンテスト
問題身長と体重
受験者sjty9561
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量88 MB
メッセージ
テストケース(通過数/総数)
2/2
状態
メモリ使用量
データパターン1
AC
83 MB
データパターン2
AC
88 MB