ソースコード
with t as (
select 
AGE,
GENDER_CODE,
case gender_code when 20 then 'MALE' when '30' then 'FEMALE' end as GENDER,
round(avg(case when category_code = 10 then average_value end), 1) H,
round(avg(case when category_code = 20 then average_value end), 1) W
from school_health
where survey_year=2019
group by 1,2,3
)

select 
AGE, GENDER, H_AVG, H_PER, W_AVG, W_PER from (
select
t.AGE, 
t.GENDER, 
t.gender_code,
t.H as H_AVG, 
(round(avg(
  case when category_code = 10 and s.average_value >= t.H then 100
  when category_code = 10 then 0 else null end
), 1) || '%') as H_PER,

t.W as W_AVG,
(round(avg(
  case when category_code = 20 and s.average_value >= t.W then 100
  when category_code = 20 then 0 else null end
), 1) || '%') as W_PER

from school_health s
inner join t on t.AGE = s.AGE and t.GENDER_CODE = s.GENDER_CODE
group by t.AGE, t.gender
) t2
order by AGE desc, gender_code desc
提出情報
提出日時2023/08/20 22:17:13
コンテスト第8回 SQLコンテスト
問題身長と体重
受験者sh_yama
状態 (詳細)WA
(Wrong Answer: 誤答)
メモリ使用量82 MB
メッセージ
テストケース(通過数/総数)
0/2
状態
メモリ使用量
データパターン1
WA
80 MB
データパターン2
WA
82 MB