ソースコード
WITH AVE AS (
    SELECT
        AGE,
        GENDER_CODE,
        AVG(
            CASE
                WHEN CATEGORY_CODE = '10' THEN AVERAGE_VALUE
            END
        ) H_AVG,
        AVG(
            CASE
                WHEN CATEGORY_CODE = '20' THEN AVERAGE_VALUE
            END
        ) W_AVG
    FROM
        SCHOOL_HEALTH
    WHERE
        SURVEY_YEAR = '2019'
    GROUP BY
        AGE,
        GENDER_CODE
),
Y_2019 AS(
    SELECT
        *
    FROM
        SCHOOL_HEALTH
    WHERE
        SURVEY_YEAR = '2019'
)
SELECT
    AGE,
    CASE
        WHEN GENDER_CODE = '20' THEN 'MALE'
        WHEN GENDER_CODE = '30' THEN 'FEMALE'
    END GENDER,
    ROUND(H_AVG, 1) H_AVG,
    ROUND(
        100.0 * COUNT(
            CASE
                WHEN CATEGORY_CODE = '10'
                AND AVERAGE_VALUE >= H_AVG THEN 1
            END
        ) / COUNT(
            CASE
                WHEN CATEGORY_CODE = '10' THEN 1
            END
        ),
        1
    ) || '%' H_PER,
    ROUND(W_AVG, 1) W_AVG,
    ROUND(
        100.0 * COUNT(
            CASE
                WHEN CATEGORY_CODE = '20'
                AND AVERAGE_VALUE >= W_AVG THEN 1
            END
        ) / COUNT(
            CASE
                WHEN CATEGORY_CODE = '20' THEN 1
            END
        ),
        1
    ) || '%' W_PER
FROM
    Y_2019
    INNER JOIN AVE USING(AGE, GENDER_CODE)
GROUP BY
    GENDER_CODE,
    AGE
ORDER BY
    AGE DESC,
    GENDER_CODE DESC
提出情報
提出日時2023/08/30 11:14:06
コンテスト第8回 SQLコンテスト
問題身長と体重
受験者asd
状態 (詳細)WA
(Wrong Answer: 誤答)
メモリ使用量82 MB
メッセージ
テストケース(通過数/総数)
0/2
状態
メモリ使用量
データパターン1
WA
78 MB
データパターン2
WA
82 MB