ソースコード
with base as (
select
    PF_CODE
    ,CATEGORY_CODE
    ,GENDER_CODE
    ,AGE
    ,round(avg(AVERAGE_VALUE) over (partition by CATEGORY_CODE,GENDER_CODE,AGE),1) as X_AVG
    ,case when round(avg(AVERAGE_VALUE) over (partition by CATEGORY_CODE,GENDER_CODE,AGE),1) <= AVERAGE_VALUE then 1 else 0 end as F
from
    SCHOOL_HEALTH   
where
    SURVEY_YEAR=2019
)
,base2 as (
select
    CATEGORY_CODE
    ,GENDER_CODE
    ,AGE
    ,X_AVG
    ,round(100.0*sum(F)/count(),1)||"%" as X_PER
from
    base
group by
    CATEGORY_CODE
    ,GENDER_CODE
    ,AGE
    ,X_AVG
)
select
    b1.AGE
    ,case when b1.GENDER_CODE ="20" then "MALE" else "FEMALE" end as GENDER
    ,b1.X_AVG as H_AVG
    ,b1.X_PER as H_PER
    ,b2.X_AVG as W_AVG
    ,b2.X_PER as W_PER
from
    base2 as b1
    inner join
    base2 as b2
    on b1.AGE=b2.AGE and b1.GENDER_CODE = b2.GENDER_CODE and b1.CATEGORY_CODE=10 and b2.CATEGORY_CODE=20
order by
    b1.AGE desc
    ,b1.GENDER_CODE desc

提出情報
提出日時2024/03/13 15:20:47
コンテスト第8回 SQLコンテスト
問題身長と体重
受験者gP2fWnUzTL
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量85 MB
メッセージ
テストケース(通過数/総数)
2/2
状態
メモリ使用量
データパターン1
AC
84 MB
データパターン2
AC
85 MB