ソースコード
create temporary table height as
select
  age,
  gender_code,
  avg(average_value) height,
  count(1) cnt
from
  school_health
where
  category_code = '10'
  and survey_year = 2019
group by age, gender_code
;

create temporary table weight as
select
  age,
  gender_code,
  avg(average_value) weight,
  count(1) cnt
from
  school_health
where
  category_code = '20'
  and survey_year = 2019
group by age, gender_code
;

create temporary table h_ans as
select
  m.age,
  m.gender_code,
  h.height H_AVG,
  round(100.0 * sum(IIF(m.average_value >= h.height, 1, 0)) / cast(h.cnt as real), 1) H_PER
from
  school_health m
left join
  height h
  on m.age = h.age and m.gender_code = h.gender_code
where
  m.category_code = '10'
  and m.survey_year = 2019
group by m.age, m.gender_code
;

create temporary table w_ans as
select
  m.age,
  m.gender_code,
  w.weight W_AVG,
  round(100.0 * sum(IIF(m.average_value >= w.weight, 1, 0)) / cast(w.cnt as real), 1) W_PER
from
  school_health m
left join
  weight w
  on m.age = w.age and m.gender_code = w.gender_code
where
  m.category_code = '20'
  and m.survey_year = 2019
group by m.age, m.gender_code
;

select
  h.age AGE,
  IIF(h.gender_code = '20', 'MALE', 'FEMALE') GENDER,
  round(h.H_AVG,1) H_AVG,
  h.H_PER || '%' H_PER,
  round(w.W_AVG,1) W_AVG,
  w.W_PER || '%' W_PER
from
  h_ans h
inner join
  w_ans w
  on h.age = w.age and h.gender_code = w.gender_code
order by AGE desc, GENDER;
提出情報
提出日時2023/08/20 11:23:05
コンテスト第8回 SQLコンテスト
問題身長と体重
受験者espressivosubito
状態 (詳細)WA
(Wrong Answer: 誤答)
メモリ使用量81 MB
メッセージ
テストケース(通過数/総数)
0/2
状態
メモリ使用量
データパターン1
WA
78 MB
データパターン2
WA
81 MB