コンテストの制限時間が終了しました。
以降も提出を行うことができますが、順位集計には反映されません。
以降も提出を行うことができますが、順位集計には反映されません。
ソースコード
WITH AvgData AS (
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
)
, HeightAboveAverage AS (
SELECT
AGE,
GENDER_CODE,
COUNT(*) AS H_ABOVE_COUNT
FROM AvgData
WHERE CATEGORY_CODE = '10' AND AVERAGE_VALUE >= H_AVG
GROUP BY AGE, GENDER_CODE
)
, WeightAboveAverage AS (
SELECT
AGE,
GENDER_CODE,
COUNT(*) AS W_ABOVE_COUNT
FROM AvgData
WHERE CATEGORY_CODE = '20' AND AVERAGE_VALUE >= W_AVG
GROUP BY AGE, GENDER_CODE
)
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 * COALESCE(h.H_ABOVE_COUNT, 0) / 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 * COALESCE(w.W_ABOVE_COUNT, 0) / COUNT(CASE WHEN s.CATEGORY_CODE = '20' THEN 1 END), 1) || '%' AS W_PER
FROM AvgData AS s
LEFT JOIN HeightAboveAverage AS h ON s.AGE = h.AGE AND s.GENDER_CODE = h.GENDER_CODE
LEFT JOIN WeightAboveAverage AS w ON s.AGE = w.AGE AND s.GENDER_CODE = w.GENDER_CODE
GROUP BY s.AGE, s.GENDER_CODE, s.H_AVG, s.W_AVG, h.H_ABOVE_COUNT, w.W_ABOVE_COUNT
ORDER BY s.AGE DESC, s.GENDER_CODE DESC;
提出情報
提出日時 | 2023/08/18 18:51:24 |
コンテスト | 第8回 SQLコンテスト |
問題 | 身長と体重 |
受験者 | imofessional |
状態 (詳細) | WA (Wrong Answer: 誤答) |
メモリ使用量 | 95 MB |
メッセージ
テストケース(通過数/総数)
0/2
状態
メモリ使用量
データパターン1
WA
95 MB
データパターン2
WA
95 MB