ソースコード
WITH SUB1 AS (
	SELECT
		AGE
		, PF_CODE
		, GENDER_CODE
		, CATEGORY_CODE
		, AVERAGE_VALUE
		, AVG(AVERAGE_VALUE) OVER (PARTITION BY AGE, GENDER_CODE, CATEGORY_CODE) DAVG
		, AVERAGE_VALUE - AVG(AVERAGE_VALUE) OVER (PARTITION BY AGE, GENDER_CODE, CATEGORY_CODE) DIFF
	FROM
		SCHOOL_HEALTH
	WHERE
		SURVEY_YEAR = 2019
)
, SUB2 AS (
    SELECT
    	AGE
    	, GENDER_CODE
    	, CATEGORY_CODE
    	, AVG(AVERAGE_VALUE) AVG_V
    	, MAX(DAVG)
    	, SUM(CASE WHEN DIFF >= 0 THEN 1 ELSE 0 END) AVG_U
    	, SUM(CASE WHEN DIFF < 0  THEN 1 ELSE 0 END) AVG_D
    FROM
    	SUB1
    GROUP BY
    	AGE
    	, GENDER_CODE
    	, CATEGORY_CODE
)
SELECT
    AGE
    , CASE WHEN GENDER_CODE = '20' THEN 'MALE' ELSE 'FEMALE' END AS GENDER
    , MAX(CASE WHEN CATEGORY_CODE = '10' THEN ROUND(AVG_V, 1) ELSE 0 END) AS 'H_AVG'
    , MAX(CASE WHEN CATEGORY_CODE = '10' THEN ROUND(CAST(AVG_U AS REAL) / (AVG_U + AVG_D) * 100, 1) ELSE 0 END)  || '%' AS 'H_PER'
    , MAX(CASE WHEN CATEGORY_CODE = '20' THEN ROUND(AVG_V, 1) ELSE 0 END) AS 'W_AVG'
    , MAX(CASE WHEN CATEGORY_CODE = '20' THEN ROUND(CAST(AVG_U AS REAL) / (AVG_U + AVG_D) * 100, 1) ELSE 0 END)  || '%' AS 'W_PER'
FROM
    SUB2
GROUP BY
    AGE
    , GENDER_CODE
ORDER BY
    AGE DESC
    , GENDER_CODE DESC
;
提出情報
提出日時2024/02/13 16:24:32
コンテスト第8回 SQLコンテスト
問題身長と体重
受験者SQL2022
状態 (詳細)WA
(Wrong Answer: 誤答)
メモリ使用量88 MB
メッセージ
テストケース(通過数/総数)
0/2
状態
メモリ使用量
データパターン1
WA
85 MB
データパターン2
WA
88 MB