ソースコード
with height as(
    select
        PF_CODE,
        AGE,
        GENDER_CODE,
        AVERAGE_VALUE,
        round(
            avg(AVERAGE_VALUE) over(partition by AGE, GENDER_CODE),
            1
        ) as H_AVG
    from
        SCHOOL_HEALTH
    where
        SURVEY_YEAR = 2019
        and CATEGORY_CODE = '10'
),
weight as(
    select
        PF_CODE,
        AGE,
        GENDER_CODE,
        AVERAGE_VALUE,
        round(
            avg(AVERAGE_VALUE) over(partition by AGE, GENDER_CODE),
            1
        ) as W_AVG
    from
        SCHOOL_HEALTH
    where
        SURVEY_YEAR = 2019
        and CATEGORY_CODE = '20'
)
select
    height.AGE as AGE,
    case
        when height.GENDER_CODE = '20' then 'MALE'
        when height.GENDER_CODE = '30' then 'FEMALE'
    end as GENDER,
    height.H_AVG,
    round(
        cast(sum(
            case
                when height.AVERAGE_VALUE >= height.H_AVG then 1
            end
        ) as real) / cast(count(height.PF_CODE) as real) * 100,
        1
    ) || '%' as H_PER,
    weight.W_AVG,
    round(
        cast(sum(
            case
                when weight.AVERAGE_VALUE >= weight.W_AVG then 1
            end
        ) as real) / cast(count(weight.PF_CODE) as real) * 100,
        1
    ) || '%' as W_PER
from
    height
    inner join weight on height.AGE = weight.AGE
    and height.GENDER_CODE = weight.GENDER_CODE
group by
    height.AGE,
    height.GENDER_CODE
order by
    height.AGE desc,
    height.GENDER_CODE desc;
提出情報
提出日時2023/08/20 23:15:06
コンテスト第8回 SQLコンテスト
問題身長と体重
受験者taka22
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量87 MB
メッセージ
テストケース(通過数/総数)
2/2
状態
メモリ使用量
データパターン1
AC
81 MB
データパターン2
AC
87 MB