ソースコード
WITH AVERAGE_TABLE AS (
    SELECT ROUND((CAST(COUNT(PF_CODE) AS REAL)/CAST(AVERAGE.PF_COUNT AS REAL))*100,1)||'%' PER ,SH.AGE,SH.GENDER_CODE,SH.CATEGORY_CODE,AVERAGE.AVG FROM SCHOOL_HEALTH SH 
        INNER JOIN (
            SELECT
                AGE,
                GENDER_CODE,
                CATEGORY_CODE,
                ROUND(AVG(AVERAGE_VALUE),1) AVG,
                COUNT(PF_CODE) PF_COUNT
                FROM SCHOOL_HEALTH
                WHERE SURVEY_YEAR = 2019 AND AVERAGE_VALUE IS NOT NULL
                GROUP BY CATEGORY_CODE, GENDER_CODE, AGE
                ) AVERAGE ON SH.AGE = AVERAGE.AGE AND SH.GENDER_CODE = AVERAGE.GENDER_CODE AND SH.CATEGORY_CODE = AVERAGE.CATEGORY_CODE
        WHERE SH.AVERAGE_VALUE >= AVG
        GROUP BY SH.AGE,SH.GENDER_CODE,SH.CATEGORY_CODE
        )
SELECT H.AGE,
    CASE
        WHEN H.GENDER_CODE=20 THEN 'MALE'
        WHEN H.GENDER_CODE=30 THEN 'FEMALE'
        ELSE ''
    END GENDER,
    H_AVG,
    H_PER,
    W_AVG,
    W_PER
 FROM (SELECT AGE,GENDER_CODE,AVG H_AVG,PER H_PER FROM AVERAGE_TABLE WHERE CATEGORY_CODE = 10) H
    INNER JOIN (SELECT AGE,GENDER_CODE,AVG W_AVG,PER W_PER FROM AVERAGE_TABLE WHERE CATEGORY_CODE = 20) W ON H.AGE=W.AGE AND H.GENDER_CODE=W.GENDER_CODE
ORDER BY H.AGE DESC, H.GENDER_CODE DESC
提出情報
提出日時2023/08/21 11:39:22
コンテスト第8回 SQLコンテスト
問題身長と体重
受験者fractal1024
状態 (詳細)WA
(Wrong Answer: 誤答)
メモリ使用量104 MB
メッセージ
テストケース(通過数/総数)
1/2
状態
メモリ使用量
データパターン1
AC
103 MB
データパターン2
WA
104 MB