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