ソースコード
with sub as (
    select
        age,
        gender_code,
        round(avg(case when category_code = '10' then average_value end), 1) as h_avg,
        round(avg(case when category_code = '20' then average_value end), 1) as w_avg
    from school_health
    where survey_year = 2019
    group by age, gender_code
)

select
    sh.age as AGE,
    case when sh.gender_code = '20' then 'MALE' else 'FEMALE' end as GENDER,
    max(h_avg) as H_AVG,
    round(100.0 * count(case when sh.category_code = '10' and sh.average_value >= sub.h_avg then 1 end) / count(case when sh.category_code = '10' then 1 end), 1) || '%' as H_PER,
    max(w_avg) as W_AVG,
    round(100.0 * count(case when sh.category_code = '20' and sh.average_value >= sub.w_avg then 1 end) / count(case when sh.category_code = '20' then 1 end), 1) || '%' as W_PER
from school_health sh
join sub on sh.survey_year = 2019 and sh.age = sub.age and sh.gender_code = sub.gender_code
group by sh.age, sh.gender_code
order by sh.age DESC, sh.gender_code desc;
提出情報
提出日時2023/08/26 23:25:31
コンテスト第8回 SQLコンテスト
問題身長と体重
受験者roaris
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量81 MB
メッセージ
テストケース(通過数/総数)
2/2
状態
メモリ使用量
データパターン1
AC
77 MB
データパターン2
AC
81 MB