ソースコード

WITH
AVERAGES AS
(SELECT
AGE,
GENDER_CODE,
CASE WHEN
GENDER_CODE = '20' THEN 'MALE'
WHEN
GENDER_CODE = '30' THEN 'FEMALE'
ELSE NULL
END AS GENDER,
ROUND(
SUM(
CASE 
WHEN CATEGORY_CODE = '10'
THEN AVERAGE_VALUE
ELSE 0
END)/
SUM(CASE WHEN
CATEGORY_CODE = '10'
THEN 1
ELSE 0 END),1) AS H_AVG,
ROUND(
SUM(
CASE 
WHEN CATEGORY_CODE = '20'
THEN AVERAGE_VALUE
ELSE 0
END)/
SUM(CASE WHEN
CATEGORY_CODE = '20'
THEN 1
ELSE 0 END),1) AS W_AVG
FROM
SCHOOL_HEALTH
WHERE SURVEY_YEAR = '2019'
GROUP BY 
AGE,GENDER
)
SELECT
t1.AGE,
GENDER,
H_AVG,
CAST(
ROUND(100.0*
SUM(CASE
WHEN AVERAGE_VALUE >= H_AVG AND CATEGORY_CODE = '10'
THEN 1
ELSE 0
END)/
SUM(
CASE WHEN CATEGORY_CODE = '10' THEN 1
ELSE 0
END)
,1) AS VARCHAR
)||'%'
AS H_PER,
W_AVG,
CAST(
ROUND(100.0*
SUM(CASE
WHEN AVERAGE_VALUE >= W_AVG AND CATEGORY_CODE = '20'
THEN 1
ELSE 0
END)/
SUM(CASE WHEN CATEGORY_CODE = '20' THEN 1
ELSE 0
END),1) AS VARCHAR) ||'%'
AS W_PER
FROM
SCHOOL_HEALTH t1
LEFT JOIN
AVERAGES t2
ON
t1.GENDER_CODE = t2.GENDER_CODE
AND
t1.AGE = t2.AGE
GROUP BY
t1.AGE,
GENDER
ORDER BY
t1.AGE DESC,
t1.GENDER_CODE DESC
提出情報
提出日時2024/07/22 17:27:24
コンテスト第8回 SQLコンテスト
問題身長と体重
受験者h_Okitsu
状態 (詳細)WA
(Wrong Answer: 誤答)
メモリ使用量88 MB
メッセージ
テストケース(通過数/総数)
0/2
状態
メモリ使用量
データパターン1
WA
88 MB
データパターン2
WA
87 MB