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