ソースコード
with h 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'
),
w 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
    h.AGE as AGE,
    case
        when h.GENDER_CODE = '20' then 'MALE'
        when h.GENDER_CODE = '30' then 'FEMALE'
    end as GENDER,
    h.H_AVG,
    round(
        sum(
            case
                when h.AVERAGE_VALUE >= h.H_AVG then 1
            end
        ) / cast(count(h.PF_CODE) as real) * 100,
        1
    ) as H_PER,
    w.W_AVG,
    round(
        sum(
            case
                when w.AVERAGE_VALUE >= w.w_AVG then 1
            end
        ) / cast(count(w.PF_CODE) as real) * 100,
        1
    ) as W_PER
from
    h
    inner join w on h.AGE = w.AGE
    and h.GENDER_CODE = w.GENDER_CODE
group by
    h.AGE,
    h.GENDER_CODE
order by
    h.AGE desc,
    h.GENDER_CODE desc
提出情報
提出日時2023/08/20 17:26:19
コンテスト第8回 SQLコンテスト
問題身長と体重
受験者visionary_band
状態 (詳細)WA
(Wrong Answer: 誤答)
メモリ使用量82 MB
メッセージ
テストケース(通過数/総数)
0/2
状態
メモリ使用量
データパターン1
WA
79 MB
データパターン2
WA
82 MB