ソースコード
with
  a as (
    select
      age,
      category_code,
      gender_code,
      round(avg(AVERAGE_VALUE), 1) av,
      count(*) cnt,
      cast(count(*) as real) cntf
    from
      SCHOOL_HEALTH
    where
      SURVEY_YEAR = 2019
    group by
      age,
      category_code,
      gender_code
  )
select 
AGE,
GENDER,
max(case category_code when '10' then av else 0.0 end) H_AVG,
max(case category_code when '10' then per else 0.0 end) H_PER,
max(case category_code when '20' then av else 0.0 end) W_AVG,
max(case category_code when '20' then per else 0.0 end) W_PER
from (
select
  sc.AGE,
  sc.category_code,
  case sc.gender_code
    when '20' then 'MALE'
    else 'FEMALE'
  end as GENDER,
  round(cast(
    sum(
      case
        when AVERAGE_VALUE >= av then 1
        else 0
      end
    ) as real
  ) *100.0 / cntf,1) || '%'  as per,
  av
from
  SCHOOL_HEALTH sc
  inner join a on sc.age = a.age
  and sc.category_code = a.category_code
  and sc.gender_code = a.gender_code
where
  sc.SURVEY_YEAR = 2019
group by
  sc.age,
  sc.category_code,
  sc.gender_code
order by
  sc.age desc,
  sc.GENDER_CODE desc)
  group by 
  age , GENDER

order by age desc, gender
提出情報
提出日時2024/04/17 00:32:03
コンテスト第8回 SQLコンテスト
問題身長と体重
受験者orekwys
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量85 MB
メッセージ
テストケース(通過数/総数)
2/2
状態
メモリ使用量
データパターン1
AC
84 MB
データパターン2
AC
85 MB